Tuesday, 21 June 2011

as keyword in c sharp

as The as operator is used to perform certain types of conversions between compatible reference types . The as operator is like a cast operation. However, if the conversion is not possible, as returns null instead of raising an exceptionExampleclass ClassA { }class ClassB { } class MainClass{    static void Main()    {        object[] objArray = new object[6];        objArray[0] = new ClassA();        objArray[1] = new ClassB();        objArray[2] = "hello";        objArray[3] = 123;        objArray[4] = 123.4;       ...

ref keyword in c sharp

ref C#The ref keyword causes arguments to be passed by reference. The effect is that any changes to the parameter in the method will be reflected in that variable when control passes back to the calling methodTo use a ref parameter, both the method definition and the calling method must explicitly use the ref keyword.An argument passed to a ref parameter must first be initialized For example:class RefExample{    static void Method(ref int i)    {        i = 44;    }    static void Main()    {        int val = 0;        Method(ref val);        // val is now 44   ...

Monday, 20 June 2011

what is static keyword in c#

static (C# Reference)The static modifier can be used with classes, fields, methods, properties, operators, events, and constructors, but it cannot be used with indexers, destructors, or types other than classes. The static modifier on a class means that the class cannot be instantiated, and that all of its members are static. The following class is declared as static and contains only static methods:static class CompanyEmployee{    public static void DoSomething() { /*...*/ }    public static void DoSomethingElse() { /*...*/  }}A constant or type declaration is implicitly a static member.A static member cannot be referenced through an instance. Instead, it is referenced through the type name. For example, consider the following classWhile an instance...

Tuesday, 14 June 2011

How to Set the Default Value of a DropDownList in an ASP.NET

DropDownList Control Examples:You can see the live samples and examples of DropDownList Control from the following links: Setting DropDownList Default ValueDropDownList Control SelectedValue PropertyDropDownList Control SelectedIndex PropertyDropDownList Control JavaScript ValidationPopulate DropDownList Items DynamicallyThe second type of situation occurs when you are updating the old data then you have to display the default value of DropDownList control as previously saved value in the database. You can use the following code to set the list item as default selected value for dropdownlist control:Example 1:DropDownList1.SelectedIndex = DropDownList1.Items.IndexOf(DropDownList1.Items.FindByText("Confections"));Example 2:DropDownList1.SelectedIndex = DropDownList1.Items.IndexOf(DropDownList1.Items.FindByValue("3"));Example...

Pages 131234 »
Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Powered by Blogger