Found 26504 Articles for Server Side Programming

Insert an element into Collection at specified index in C#

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

371 Views

To insert an element into Collection at the specified index, 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("Laptop");       col.Add("Desktop");       col.Add("Notebook");       col.Add("Ultrabook");       col.Add("Tablet");       col.Add("Headphone");       col.Add("Speaker");       Console.WriteLine("Elements in Collection...");       foreach(string str in col){          Console.WriteLine(str);       }       Console.WriteLine("Element at index 3 = " + col[3]);     ... Read More

Insert a new entry in OrderedDictionary with specified key and value in C#

AmitDiwan
Updated on 11-Dec-2019 06:41:26

122 Views

To insert a new entry in OrderedDictionary with specified key and value, the code is as follows −Example Live Demousing System; using System.Collections; using System.Collections.Specialized; public class Demo {    public static void Main(){       OrderedDictionary dict = new OrderedDictionary();       dict.Add("1", "One");       dict.Add("2", "Two");       dict.Add("3", "Three");       dict.Add("4", "Four");       dict.Add("5", "Five");       dict.Add("6", "Six");       dict.Add("7", "Seven");       dict.Add("8", "Eight");       Console.WriteLine("Elements...");       IDictionaryEnumerator demoEnum = dict.GetEnumerator();       while (demoEnum.MoveNext()) {     ... Read More

Check whether an element is contained in the ArrayList in C#

AmitDiwan
Updated on 11-Dec-2019 06:38:41

191 Views

To check whether an element is contained in the ArrayList, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main(){       ArrayList list = new ArrayList();       list.Add("One");       list.Add("Two");       list.Add("Three");       list.Add("Four");       list.Add("Five");       list.Add("Six");       list.Add("Seven");       list.Add("Eight");       Console.WriteLine("ArrayList elements...");       foreach(string str in list){          Console.WriteLine(str);       }       Console.WriteLine("ArrayList is read-only? = "+list.IsReadOnly);     ... Read More

Check whether a Hashtable contains a specific key or not in C#

AmitDiwan
Updated on 11-Dec-2019 06:35:31

162 Views

To check whether a Hashtable contains a specific key or not, 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("One", "Katie");       hash.Add("Two", "John");       hash.Add("Three", "Barry");       hash.Add("Four", "");       hash.Add("Five", "Harry");       hash.Add("Six", "F");       hash.Add("Seven", "Tom");       hash.Add("Eight", "Andy");       hash.Add("Nine", "I");       hash.Add("Ten", "Tim");       Console.WriteLine("Hashtable Key and Value pairs...");       foreach(DictionaryEntry ... Read More

Check the HybridDictionary for a specific key in C#

AmitDiwan
Updated on 11-Dec-2019 06:32:29

113 Views

To check the HybridDictionary for a specified key, the code is as follows −Example Live Demousing System; using System.Collections; using System.Collections.Specialized; public class Demo {    public static void Main(){       HybridDictionary dict = new HybridDictionary(5);       dict.Add("A", "AB");       dict.Add("B", "BC");       dict.Add("C", "DE");       dict.Add("D", "FG");       dict.Add("E", "HI");       Console.WriteLine("Key/Value pairs...");       foreach(DictionaryEntry d in dict)       Console.WriteLine("Key = "+d.Key + ", Value = " + d.Value);       Console.WriteLine("Does HybridDictionary contains the key C? = "+dict.Contains("C"));    } ... Read More

Convert Class in C#

AmitDiwan
Updated on 11-Dec-2019 06:29:45

720 Views

The Convert Class has methods to convert a base data type to another base data type. Let us see some examples −The Convert.ToBoolean() method in C# is used to convert a specified value to an equivalent Boolean value.SyntaxFollowing is the syntax −public static bool ToBoolean (string val, IFormatProvider provider);Above, Val is a string that contains the value of either TrueString or FalseString, whereas the provider is an object that supplies culture-specific formatting information.ExampleLet us now see an example to implement the Convert.ToBoolean() method − Live Demousing System; using System.Globalization; public class Demo {    public static void Main(){       ... Read More

Char Struct in C#

AmitDiwan
Updated on 11-Dec-2019 06:26:39

411 Views

The Char Struct in C# represents a character as a UTF-16 code unit. Here are some of the methods −MethodDescriptionConvertToUtf32(Char, Char)Converts the value of a UTF-16 encoded surrogate pair into a Unicode code point.ConvertToUtf32(String, Int32)Converts the value of a UTF-16 encoded character or surrogate pair at a specified position in a string into a Unicode code point.Equals(Char)Returns a value that indicates whether this instance is equal to the specified Char object.Equals(Object)Returns a value that indicates whether this instance is equal to a specified object.GetHashCode()Returns the hash code for this instance.GetNumericValue(Char)Converts the specified numeric Unicode character to a double-precision floating-point number.IsDigit(String, ... Read More

Getting the Standard Output and Standard Error Output Stream through Console in C#

AmitDiwan
Updated on 11-Dec-2019 06:24:33

648 Views

To get the standard output stream through Console, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main(string[] args){       Console.WriteLine("Standard Output Stream = "+Console.Out);    } }OutputThis will produce the following output −Standard Output Stream = System.IO.TextWriter+SyncTextWriterExampleTo get the standard error output stream through Console, the code is as follows − Live Demousing System; public class Demo {    public static void Main(string[] args){       Console.WriteLine("Standard Output Stream = "+Console.Out);       Console.WriteLine("Standard Error Output Stream = "+Console.Error);    } }OutputThis will produce the following output −Standard Output ... Read More

Getting the Largest Window Height and Width of the Console in C#

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

232 Views

To get the largest window height of the Console, the code is as follows −Example Live Demousing System; public class Demo{    public static void Main(string[] args){       Console.WriteLine("Largest Window Height of the Console = "+Console.LargestWindowHeight);    } }OutputThis will produce the following output −Largest Window Height of the Console = 58ExampleTo get the largest window width of the Console, the code is as follows − Live Demousing System; public class Demo{    public static void Main(string[] args){       Console.WriteLine("Largest Window Width of the Console = "+Console.LargestWindowWidth);    } }OutputThis will produce the following output −Largest Window Width of the Console = 190

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

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

96 Views

To get the fourth 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 5th = "+tuple1.Item5);       Console.WriteLine("Tuple2 Item 5th = "+tuple2.Item5);       Console.WriteLine("Tuple1 Item 1st ... Read More

Advertisements