Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you use optional parameters in code targeting .NET 3.5?

I'm looking to write a library that uses the new optional parameters feature of C# 4.0, but I want to target it to the 3.5 version of the framework. Is this possible?

Are optional parameters syntactic sugar in the same way that extension methods are?

like image 305
Charles Graham Avatar asked Jul 31 '09 04:07

Charles Graham


People also ask

Can we have optional out parameter C#?

Func(out i); then the answer is no you cant. also C# and . NET framework hast many many data structures that are very flexible like List and Array and you can use them as an output parameter or as return type so there is no need to implement a way to have optional output parameters.

Can parameters be optional?

The definition of a method, constructor, indexer, or delegate can specify its parameters are required or optional. Any call must provide arguments for all required parameters, but can omit arguments for optional parameters. Each optional parameter has a default value as part of its definition.

How do you pass optional parameters in C#?

By Params Keyword: You can implement optional parameters by using the params keyword. It allows you to pass any variable number of parameters to a method. But you can use the params keyword for only one parameter and that parameter is the last parameter of the method.


1 Answers

With VS2010 RC, I was able to create a .NET 3.5 application that uses optional parameters in C#.

So yes, it's all about syntactic sugar.

like image 170
Bernard Vander Beken Avatar answered Sep 22 '22 06:09

Bernard Vander Beken