C# Default Arguments [Optional Arguments]

Monday, September 05, 2011

Coming from the C++ world, one of the things I missed in C# was the support for Default Arguments. Default arguments are used to create functions which could have a few optional arguments with default values. Thus, you could make overloaded calls to the method without creating different function prototypes if the purpose could by using a default value of one of the parameters. Many other common languages like PHP, VB.NET, JavaScript etc. also support this feature. It was surprising that C# did not support it.

With C# 4.0 (2010), the support for this feature has been added to the language. The new Optional Arguments in C# 4.0 allows you to specify the default values of parameters in case there values are not provided from the function call. Here's a small example to illustrate the basics of Optional Arguments in C#:


// Function with optional arguments
void OptionalArgExample(int reqdField, string opt = "default value")
// do something

// Calling the method with just the required argument

// Calling the method with both the arguments
OptionalArgExample(10, "some text");

For more information, read the MSDN article on Named and Optional Arguments in C#

Troubleshooting Remote Desktop's Copy/Paste

Thursday, September 01, 2011

If you use Window's RDP to remote into your computer or server regularly, you might have noticed that sometimes the Copy and Paste functionality stops working. This functionality is often needed when you work with remote systems as you would frequently want to copy paste text to search for some help; copy some documents which would be easier to read on your computer than on the slow VPN connection you are connected to or maybe if you want to copy something a backup. Usually, to fix this I have to turn off my session and create a new session, which is really cumbersome. But, recently I found a really easy method to fix this situation here. Here's what you need to do to six the issue:

  • Open Task Manager (Ctrl+Shift+Esc) on the remote machine.
  • Find the "rdpclip" process and kill it.
  • Run "rdpclip" to start it again.
Just follow the above steps and your Copy/Paste functionality will start working again between the remote and the host computer. This is a real time-saver when dealing with the issue.

Another alternate is to use a internet clipboard site like cl1p.net, which allows you to create a private clipboard which could be accessed from any computer. Also, I've sometimes used GMail to accomplish this by creating a new draft email and opening it from the other host. These methods are also useful if you want to copy data between different computers.