-4

Im fairly new to c# programming. What does passing a parameter mean? and can someone give me an example please?

Thank you.

Dan
  • 17
  • 1
  • 4
  • 14
    Stack Overflow isn't really a good site to learn a language from scratch. I suggest you get a good introductory book, which should cover this along with everything else. I *do* have an [article on parameter passing](http://pobox.com/~skeet/csharp/parameters.html) but if you don't know anything about parameters to start with, it's unlikely to be terribly helpful. – Jon Skeet Sep 13 '13 at 08:16
  • [Passing Parameters (C# Programming Guide)](http://msdn.microsoft.com/en-us/library/0f66670z.aspx) – Soner Gönül Sep 13 '13 at 08:17
  • 1
    Your question doesn't directly relate to C#. You must first learn **thinking in a computer program** and then **programming** – Alireza Sep 13 '13 at 08:17
  • [It's not a C# concept.](http://en.wikipedia.org/wiki/Parameter_(computer_programming)) Also, the Stack Overflow community doesn't like questions which can be answered by a simple [google search (about 26,600,000 results)](https://www.google.com/search?q=passing+a+parameter). – vgru Sep 13 '13 at 08:19

2 Answers2

1

Functions in languages such as C# (and many, many, others) can take "parameters". These are things you pass in to let the function do whatever it was designed to do. Consider:

public int Add(int x, int y)
{
   return x + y;
}

int a = 5;
int b = 5;

int sum = Add(a, b);

In the above example, we are passing the variables a and b to the function Add. The function takes two parameters, x and y, and adds them together returning the result.

Moo-Juice
  • 38,257
  • 10
  • 78
  • 128
0

In simple sense,passing a parameter means to give an input to the function. let me give you an example

below is the algorithm for adding two numbers and printing the result

void add(int a,int b)
{
    int sum
    sum=a+b
    print sum 
}

So we have defined a function. The function add contains two arguments. An argument is a 'holder' for the values ie a variable.Now it expects two parameters( input) a and b.

Hence to use this function we must call it like this

add(1,2) 

the numbers inside the paranthesis are called parameters. they are input for your function

BenMorel
  • 34,448
  • 50
  • 182
  • 322
  • Yes :) I don't know c#. so I used a psuedocode to clarify it. Thankx for the notice and edit :) –  Sep 13 '13 at 08:23
  • Your "pseudocode" function nevertheless seems like it could use a return statement. – vgru Sep 13 '13 at 08:24
  • Edited. Sorry but I am still newbie in programming –  Sep 13 '13 at 08:26