Click here to Skip to main content
Rate this: bad
good
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 23:27pm
Edited 23-Jan-13 23:29pm
v2

1 solution

Rate this: bad
good
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.
  Permalink  

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 223
1 Abhinav S 170
2 Richard Deeming 155
3 CHill60 150
4 Maciej Los 145
0 Sergey Alexandrovich Kryukov 7,156
1 OriginalGriff 6,410
2 Maciej Los 2,877
3 Abhinav S 2,732
4 Peter Leow 2,694


Advertise | Privacy | Mobile
Web03 | 2.8.150414.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