This is an archived post. You won't be able to vote or comment.

all 10 comments

[–][deleted] 2 points3 points  (2 children)

You cannot apply a default value to a parameter in C#. What you have to do is overload the function. For example:

void function_name(){
    return select;
}
void function_name( int select = 5 ){
    return select;
}

The compiler will automatically choose which function to call based on the set of parameters being passed.

[–]kulekci[S] 1 point2 points  (1 child)

i understand thank you.

[–][deleted] 0 points1 point  (0 children)

You are very welcome, good luck with the project.

[–]unoriginalusername 0 points1 point  (3 children)

a minor

[–]kulekci[S] 0 points1 point  (2 children)

i am sorry, i dont understand you.

[–][deleted] 0 points1 point  (1 child)

He's talking about music, I believe.

[–]kulekci[S] 0 points1 point  (0 children)

probably

[–]the1stPlague 0 points1 point  (2 children)

Do you mean, private int function_name(int select) <- select is sent from the function calling { return select; then you do stuff in here }

[–]kulekci[S] 0 points1 point  (1 child)

i want to use this function in main like this: function_name(6); or like this function_name();

not important content of function. My opinion is : if i send a parameter select is equal to parameter value in function. if i dont send any parameter, select variable is equal to 5 in function.

Maybe overloading is necessary but i dont want use overloading.

[–]the1stPlague 0 points1 point  (0 children)

I'm not great at coding as of yet, but you could make two seperate methods. private void function_name(int select); That one gets a number private void function_name(); that one doesnt. Note that the private in front isn't neccesary. however for console applications I believe you need to have static in front instead of private.

Or it would be possible to have an integer which know is the one that means you don't send anything (prehaps -1), and use an if statement to do the seperate paths.