Click here to Skip to main content
13,086,266 members (89,341 online)
Rate this:
Please Sign up or sign in to vote.
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
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
Updated 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
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170813.1 | Last Updated 24 Jan 2013
Copyright © CodeProject, 1999-2017
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