Click here to Skip to main content
11,791,059 members (47,667 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C#4.0
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
public void ExampleMethod(int required, string optionalstr = "default string",
    int optionalint = 10)
The usage of it
anExample.ExampleMethod(3, optionalint: 4); 
For more info you can see it in MSDN[^]
So I need something like
public void ExampleMethod(int required, List<string> optionalstrList = "????",
    int optionalint = 10)
Posted 23-Jan-13 22:27pm
Edited 23-Jan-13 22:29pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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

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

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

  Print Answers RSS
0 OriginalGriff 1,329
1 Maciej Los 835
2 ppolymorphe 780
3 KrunalRohit 686
4 CPallini 661

Advertise | Privacy | Mobile
Web03 | 2.8.1509028.1 | Last Updated 24 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100