Click here to Skip to main content
15,913,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,

My purpose is to have an argument on a method. This argument is going to be a list. But this argument is going to be used as an optional argument and its default value should be a empty list. How can I declare it?

As an example
C#
public void ExampleMethod(int required, string optionalstr = "default string",
    int optionalint = 10)

The usage of it
C#
anExample.ExampleMethod(3, optionalint: 4); 

For more info you can see it in MSDN[^]
So I need something like
C#
public void ExampleMethod(int required, List<string> optionalstrList = "????",
    int optionalint = 10)
Posted
Updated 23-Jan-13 22:29pm
v2

1 solution

C#
public void Example(List<something> list = null) { /*...*/  }</something>


But I'm not sure to clearly understand what your problem is.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900