.net - How to pass optional parameters to a method in C#? -


How to pass the optional parameters for a method in C #?

Suppose I have made a command called a command called Sendcommand.

) // List the files from the server {// code} else if (command == "STOR" + Path.GetFileName (uploadfilename)) // upload the file to the server {// code} else if ...}

Now I want to call this method in main mode like

  Sendcommand ("STOR", filename); Sendcommand ("list"); // In this case I do not want to give the second parameter  

How to get it?

Use the paramet attribute:

  Public Zero SendCommand (string Command, parameter string [strfilename] {}  

Then you can call it like this:

  SendCommand ("cmd"); Send Command ("CMD", "A"); Send Command ("CMD", "B");  

Or if you use C # 4.0, you can use the new optional logic feature You can use:

  Public Zero SendCommand (string command, string s Trfilename = null) {if (strfelname! = Null) ..}  

Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -