Found 26504 Articles for Server Side Programming

Get the type referenced by the specified type handle in C#

AmitDiwan
Updated on 10-Dec-2019 07:36:55

210 Views

To get the type referenced by the specified type handle, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main() {       Type type1 = typeof(short);       RuntimeTypeHandle typeHandle = Type.GetTypeHandle(type1);       Type type = Type.GetTypeFromHandle(typeHandle);       Console.WriteLine("Attributes = " + type.Attributes);    } }OutputThis will produce the following output −Attributes = AutoLayout, AnsiClass, Class, Serializable, BeforeFieldInitExampleLet us see another example − Live Demousing System; public class Demo {    public static void Main() {       Type type1 = typeof(System.Type);       RuntimeTypeHandle ... Read More

Convert a specified value to an equivalent Boolean value in C#

AmitDiwan
Updated on 10-Dec-2019 07:33:49

465 Views

To convert a specified value to an equivalent Boolean value, the code is as follows −Example Live Demousing System; using System.Globalization; public class Demo {    public static void Main() {       CultureInfo cultures = new CultureInfo("en-US");       String str = "true";       Console.WriteLine("Converted bool value...");       bool res = Convert.ToBoolean(str, cultures);       Console.Write("{0}", res);    } }OutputThis will produce the following output −Converted bool value... TrueExampleLet us see another example − Live Demousing System; using System.Globalization; public class Demo {    public static void Main() {       CultureInfo cultures ... Read More

Gets or sets the value in HybridDictionary with specified key in C#

AmitDiwan
Updated on 10-Dec-2019 07:28:29

148 Views

To get or set the value in HybridDictionary with specified key, the code is as follows −Example Live Demousing System; using System.Collections.Specialized; public class Demo {    public static void Main() {       HybridDictionary myDict = new HybridDictionary();       myDict.Add("1", "Tablet");       myDict.Add("2", "Desktop");       myDict.Add("3", "Speakers");       myDict.Add("4", "Laptop");       myDict.Add("5", "Notebook");       myDict.Add("6", "Ultrabook");       myDict.Add("7", "HDD");       myDict.Add("8", "SDD");       Console.WriteLine("Value at key 5 = "+myDict["5"]);    } }OutputThis will produce the following output −Value at key 5 ... Read More

Gets or sets the value at the specified key in StringDictionary in C#

AmitDiwan
Updated on 10-Dec-2019 07:12:16

118 Views

To get or set the value at the specified key in StringDictionary, the code is as follows −Example Live Demousing System; using System.Collections.Specialized; public class Demo {    public static void Main() {       StringDictionary myDict = new StringDictionary();       myDict.Add("1", "Tablet");       myDict.Add("2", "Desktop");       myDict.Add("3", "Speakers");       myDict.Add("4", "Laptop");       myDict.Add("5", "Notebook");       myDict.Add("6", "Ultrabook");       myDict.Add("7", "HDD");       myDict.Add("8", "SDD");       myDict.Add("9", "Headphone");       myDict.Add("10", "Earphone");       Console.WriteLine("Value for key 5 = "+myDict["5"]);   ... Read More

Remove all the strings from the StringCollection in C#

AmitDiwan
Updated on 10-Dec-2019 07:09:38

138 Views

To remove all the strings from the StringCollection, the code is as follows −Example Live Demousing System; using System.Collections.Specialized; public class Demo {    public static void Main() {       StringCollection stringCol = new StringCollection();       String[] arr = new String[] { "100", "200", "300", "400", "500" };       Console.WriteLine("Array elements...");       foreach (string res in arr) {          Console.WriteLine(res);       }       stringCol.AddRange(arr);       Console.WriteLine("Does the specified string is in the StringCollection? = "+stringCol.Contains("800"));       Console.WriteLine("Total number of elements = "+stringCol.Count); ... Read More

Removing all the elements from the List in C#

AmitDiwan
Updated on 10-Dec-2019 07:05:10

161 Views

To remove all the elements from the List, the code is as follows −Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main(String[] args) {       List list1 = new List();       list1.Add("One");       list1.Add("Two");       list1.Add("Three");       list1.Add("Four");       list1.Add("Five");       Console.WriteLine("Elements in List1...");       foreach (string res in list1) {          Console.WriteLine(res);       }       List list2 = new List();       list2.Add("India");       list2.Add("US");       ... Read More

Get the number of elements contained in Collection in C#

AmitDiwan
Updated on 10-Dec-2019 06:59:45

121 Views

To get the number of elements contained in Collection, the code is as follows −Example Live Demousing System; using System.Collections.ObjectModel; public class Demo {    public static void Main() {       Collection col = new Collection();       col.Add("Andy");       col.Add("Kevin");       col.Add("John");       col.Add("Kevin");       col.Add("Mary");       col.Add("Katie");       col.Add("Barry");       col.Add("Nathan");       col.Add("Mark");       Console.WriteLine("Count of elements = "+ col.Count);       Console.WriteLine("Iterating through the collection...");       var enumerator = col.GetEnumerator();       while ... Read More

Gets or Sets the element at the specified index in the List in C#

AmitDiwan
Updated on 10-Dec-2019 06:55:43

152 Views

To get or set the element ate the specified index in the List, the code is as follows −Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main(String[] args) {       List list = new List();       list.Add("100");       list.Add("200");       list.Add("300");       list.Add("400");       list.Add("500");       list.Add("600");       list.Add("700");       list.Add("800");       list.Add("900");       list.Add("1000");       Console.WriteLine("Element at index 0 = " + list[0]);       Console.WriteLine("Element at index 1 ... Read More

Gets or sets the element at the specified index in StringCollection in C#

AmitDiwan
Updated on 10-Dec-2019 06:47:59

90 Views

To get or set the element at the specified index in StringCollection, the code is as follows −Example Live Demousing System; using System.Collections.Specialized; public class Demo {    public static void Main() {       StringCollection strCol = new StringCollection();       String[] strArr = new String[] { "A", "B", "C", "D", "E", "F", "G", "H" };       Console.WriteLine("StringCollection elements...");       foreach (string str in strArr) {          Console.WriteLine(str);       }       strCol.AddRange(strArr);       Console.WriteLine("Element at 5th index = "+strCol[5]);       Console.WriteLine("Count of strings ... Read More

Gets an ICollection containing the values in the Hashtable in C#

AmitDiwan
Updated on 10-Dec-2019 06:42:56

106 Views

To get an ICollection containing the values in the Hashtable, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main() {       Hashtable hash = new Hashtable();       hash.Add("A", "Electronics");       hash.Add("B", "Appliances");       hash.Add("C", "Pet Supplies");       hash.Add("D", "Books");       hash.Add("E", "Toys");       hash.Add("F", "Footwear");       hash.Add("G", "Clothing");       ICollection col = hash.Keys;       foreach(string str in col)       Console.WriteLine(str + ": " + hash[str]);    } }OutputThis ... Read More

Advertisements