Home Python C Language C ++ HTML 5 CSS Javascript Java Kotlin SQL DJango Bootstrap React.js R C# PHP ASP.Net Numpy Dart Pandas Digital Marketing

C# Methods Parameters:


Of course! In C#, method parameters are like variables that you give to a method so it can use them to do its job. Here's a simple explanation with an example:

Explanation:

Example:

Let's create a method called Greet that takes a person's name as a parameter and prints a greeting message.

Example

using System;

class Program
{
// Method to greet a person
static void Greet(string name)
{
Console.WriteLine("Hello, " + name + "!"); // Printing the greeting message
}

static void Main(string[] args)
{
string userName = "Alice";
Greet(userName); // Calling the method with the parameter "Alice"

string friendName = "Bob";
Greet(friendName); // Calling the method with the parameter "Bob"
}
}

In this example:

So, when you run this program, it will output:

Example

Hello, Alice!
Hello, Bob!

This demonstrates how you can use method parameters to pass data to a method and make your code more dynamic.



Advertisement





Q3 Schools : India


Online Complier

HTML 5

Python

java

C++

C

JavaScript

Website Development

HTML

CSS

JavaScript

Python

SQL

Campus Learning

C

C#

java