Click here to Skip to main content
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 Sergey Alexandrovich Kryukov 529
1 OriginalGriff 307
2 Damith Weerasinghe 295
3 ravikhoda 260
4 Tadit Dash 180
0 Sergey Alexandrovich Kryukov 10,974
1 OriginalGriff 6,667
2 Peter Leow 4,760
3 Abhinav S 3,813
4 Maciej Los 3,565

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