Posts

Showing posts from April, 2013

SaveSetting and GetSetting in C#

How to use SaveSetting() and GetSetting() methods of VB in C#? Lets see, SaveSetting() method is used to store UI input data and GetSetting() method is used to retrieve that stored data. //Save textbox1's value SaveSetting (App.EXEName, "textboxes", "textbox1", textbox1.Text) //Get textbox1's value textbox1.text = GetSetting (App.EXEName, "textboxes", "textbox1", "") SaveSetting stores the data in the Registry (in HKEY_CURRENT_USER|Software|VB and VBA Program Settings|YourAppName). The four parts of the function are the name under which it is stored (App.EXEName in this case), "textboxes" in this example is like the section name in an ini file, "textbox1" is like the key in a line of data in the ini file, and textbox1.text is the value. GetSetting returns the value. The 4th parameter ("" in this case) is optional and it is the default if no registry entry is found. I f you use thes...

C# Optional Parameter

How to use Optional Parameters in Method? An  optional parameter  has a default value. A method with an optional parameter can be called with only some of its parameters specified. Following two code snippet shows how to work with optional parameters in C#. (1) public void method(int a, string optParam="defaultValue") {       //Appropriate code here; } In above example second string parameter  optParam is passed with default value " defaultValue ". When method() is called with only one parameter then second parameter automatically assigned to its default value.       method(25);  // here second parameter gets value " defaultValue ".           or    method(25,"Example"); //here second parameter gets value "Example". Other method to pass optional parameter is, (2) using System.Runtime.InteropServices; public void method(int a, [Optional] string...