Found 2628 Articles for Csharp

Get the number of strings in StringCollection in C#

AmitDiwan
Updated on 05-Dec-2019 12:18:59

46 Views

To get the number of strings 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 in StringCollection = " ... Read More

Get or set the value associated with the specified key in StringDictionary in C#

AmitDiwan
Updated on 05-Dec-2019 12:14:47

63 Views

To get or set the value associated with 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 strDict = new StringDictionary ();       strDict.Add("A", "Books");       strDict.Add("B", "Electronics");       strDict.Add("C", "Appliances");       strDict.Add("D", "Pet Supplies");       strDict.Add("E", "Clothing");       strDict.Add("F", "Footwear");       Console.WriteLine("Value associated with key D = "+strDict["D"]);       Console.WriteLine("Value associated with key F = "+strDict["F"]);    } }OutputThis will produce the following output ... Read More

Remove from the specified index of the StringCollection in C#

AmitDiwan
Updated on 05-Dec-2019 12:10:53

83 Views

To remove from the specified index of 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("Total number of elements = "+stringCol.Count);       stringCol.RemoveAt(3);       Console.WriteLine("Total number of elements ... Read More

How to get Seventh Element of the Tuple in C#?

AmitDiwan
Updated on 05-Dec-2019 12:06:35

52 Views

To get seventh element of the Tuple, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main(String[] args) {       var tuple1 = Tuple.Create(75, 200, 500, 700, 100, 1200, 1500);       var tuple2 = Tuple.Create(75, 200, 500, 700, 100, 1200, 1500);       Console.WriteLine("Is Tuple1 equal to Tuple2? = "+tuple1.Equals(tuple2));       Console.WriteLine("HashCode of Tuple1 = "+tuple1.GetHashCode());       Console.WriteLine("HashCode of Tuple2 = "+tuple2.GetHashCode());       Console.WriteLine("Tuple1 Item 1st = "+tuple1.Item1);       Console.WriteLine("Tuple2 Item 1st = "+tuple2.Item1);       Console.WriteLine("Tuple1 Item 2nd ... Read More

Remove all elements from the Hashtable in C#

AmitDiwan
Updated on 05-Dec-2019 12:03:24

134 Views

To remove all elements from 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(10);       hash.Add("1", "A");       hash.Add("2", "B");       hash.Add("3", "C");       hash.Add("4", "D");       hash.Add("5", "E");       hash.Add("6", "F");       hash.Add("7", "G");       hash.Add("8", "H");       hash.Add("9", "I");       hash.Add("10", "J");       Console.WriteLine("Hashtable Key and Value pairs...");       foreach(DictionaryEntry entry in hash) ... Read More

Remove all elements from the Collection in C#

AmitDiwan
Updated on 05-Dec-2019 11:58:52

298 Views

To remove all elements from the 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(10);       col.Add(20);       col.Add(30);       col.Add(40);       col.Add(50);       col.Add(60);       col.Add(70);       col.Add(80);       Console.WriteLine("Elements in the Collection...");       foreach(int val in col) {          Console.WriteLine(val);       }       Console.WriteLine("Does the collection has the element ... Read More

Check whether the specified Unicode character is a punctuation mark in C#

AmitDiwan
Updated on 05-Dec-2019 11:53:57

194 Views

To check whether the specified Unicode character is a punctuation mark, the code is as follow −Example Live Demousing System; public class Demo {    public static void Main() {       bool res;       char val = 'q';       Console.WriteLine("Value = "+val);       res = Char.IsPunctuation(val);       Console.WriteLine("Is the value a punctuation? = "+res);    } }OutputThis will produce the following output −Value = q Is the value a punctuation? = FalseExampleLet us see another example − Live Demousing System; public class Demo {    public static void Main() {     ... Read More

Get the hash code for the current Int64 instance in C#

AmitDiwan
Updated on 05-Dec-2019 11:51:00

94 Views

To get the hash code for the current Int64 instance, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main() {       long val1 = 8768768768;       long val2 = 7889765555;       Console.WriteLine("Value1 = "+val1);       Console.WriteLine("Value2 = "+val2);       Console.WriteLine("Are they equal? = "+val1.Equals(val2));       Console.WriteLine("Value1 (HashCode) = "+val1.GetHashCode());       Console.WriteLine("Value2 (HashCode) = "+val2.GetHashCode());    } }OutputThis will produce the following output −Value1 = 8768768768 Value2 = 7889765555 Are they equal? = False Value1 (HashCode) = 178834178 Value2 (HashCode) = -700169038ExampleLet us see another example − Live Demousing System; public class Demo { ... Read More

Compare this instance is equal to a specified object or Int64 in C#

AmitDiwan
Updated on 05-Dec-2019 11:45:31

51 Views

To compare this instance is equal to a specified object or Int64, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main() {       long val1 = 150;       long val2 = 240;       Console.WriteLine("Value1 = "+val1);       Console.WriteLine("Value2 = "+val2);       Console.WriteLine("Are they equal? = "+val1.Equals(val2));    } }OutputThis will produce the following output −Value1 = 150 Value2 = 240 Are they equal? = FalseExampleLet us see another example − Live Demousing System; public class Demo {    public static void Main() {       long val1 = ... Read More

Check whether the Unicode character is a lowercase letter in C#

AmitDiwan
Updated on 05-Dec-2019 11:30:32

124 Views

To check whether the Unicode character is a lowercase letter, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main() {       bool res;       char val = 'K';       Console.WriteLine("Value = "+val);       res = Char.IsLower(val);       Console.WriteLine("Is the value a lowercase letter? = "+res);    } }OutputThis will produce the following output −Value = K Is the value a lowercase letter? = FalseExampleLet us see another example − Live Demousing System; public class Demo {    public static void Main() {   ... Read More

Advertisements