Found 26504 Articles for Server Side Programming

Get or set the element at specified index in Collection in C#

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

263 Views

To get or set the element at specified index 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("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 = " + ... Read More

Get or Set at specified index in StringCollection in C#

AmitDiwan
Updated on 10-Dec-2019 05:58:23

146 Views

To get or set at 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]);    } }OutputThis will produce the following output −StringCollection elements... ... Read More

Check if SortedSet and a specified collection share common elements in C#

AmitDiwan
Updated on 10-Dec-2019 05:55:19

103 Views

To check if SortedSet and a specified collection share common element, the code is as follows −Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main() {       SortedSet set1 = new SortedSet();       set1.Add(100);       set1.Add(200);       set1.Add(300);       set1.Add(400);       set1.Add(500);       set1.Add(600);       SortedSet set2 = new SortedSet();       set2.Add(100);       set2.Add(200);       set2.Add(300);       set2.Add(400);       set2.Add(500);       set2.Add(600);       Console.WriteLine("Does it ... Read More

Capacity of a SortedList in C#

AmitDiwan
Updated on 09-Dec-2019 06:27:26

168 Views

To get the capacity of a SortedList, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main(String[] args){       SortedList sortedList = new SortedList();       sortedList.Add("A", "1");       sortedList.Add("B", "2");       sortedList.Add("C", "3");       sortedList.Add("D", "4");       sortedList.Add("E", "5");       sortedList.Add("F", "6");       sortedList.Add("G", "7");       sortedList.Add("H", "8");       sortedList.Add("I", "9");       sortedList.Add("J", "10");       Console.WriteLine("SortedList elements...");       foreach(DictionaryEntry d in sortedList){       ... Read More

Check whether the Unicode character is a separator character in C#

AmitDiwan
Updated on 09-Dec-2019 06:24:15

250 Views

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

Convert Decimal to equivalent 8-bit unsigned integer in C#

AmitDiwan
Updated on 09-Dec-2019 06:21:28

284 Views

To convert the value of the specified Decimal to the equivalent 8-bit unsigned integer, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main(){       Decimal val1 = 6.59m;       Decimal val2 = 30.12m;       Decimal val3 = 69.34m;       Console.WriteLine("Decimal 1 = "+val1);       Console.WriteLine("Decimal 2 = "+val2);       Console.WriteLine("Decimal 3 = "+val3);       byte res1 = Decimal.ToByte(val1);       byte res2 = Decimal.ToByte(val2);       byte res3 = Decimal.ToByte(val3);       Console.WriteLine("Byte value1 (Decimal ... Read More

Get the TypeCode for value type Decimal in C#

AmitDiwan
Updated on 09-Dec-2019 06:15:28

174 Views

To get the TypeCode for value type Decimal, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main(){       Decimal val = Decimal.MaxValue;       Console.WriteLine("Decimal Value = {0}", val);       Console.WriteLine("HashCode = {0}", (val.GetHashCode()) );       TypeCode type = val.GetTypeCode();       Console.WriteLine("TypeCode = "+type);    } }OutputThis will produce the following output −Decimal Value = 79228162514264337593543950335 HashCode = 1173356544 TypeCode = DecimalExampleLet us now see another example − Live Demousing System; public class Demo {    public static void Main(){     ... Read More

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

AmitDiwan
Updated on 09-Dec-2019 06:11:04

154 Views

To get the hash code for the current Decimal instance, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main(){       Decimal val = 135269.38193M;       Console.WriteLine("Decimal Value = {0}", val);       Console.WriteLine("HashCode = {0}", (val.GetHashCode()) );    } }OutputThis will produce the following output −Decimal Value = 135269.38193 HashCode = 1328665595ExampleLet us now see another example − Live Demousing System; public class Demo {    public static void Main(){       Decimal val = Decimal.MaxValue;       Console.WriteLine("Decimal Value = {0}", val);       Console.WriteLine("HashCode = {0}", (val.GetHashCode()) );    } }OutputThis will produce the following output −Decimal Value = 79228162514264337593543950335 HashCode = 1173356544

Convert the specified string representation of a logical value to its Boolean equivalent in C#

AmitDiwan
Updated on 09-Dec-2019 06:08:28

112 Views

To convert the specified string representation of a logical value to its Boolean equivalent, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main(){       bool val;       bool flag;       val = Boolean.TryParse("true", out flag);       Console.WriteLine("Result = "+val);    } }OutputThis will produce the following output −Example Live Demousing System; public class Demo {    public static void Main() {       bool val; bool flag;       val = Boolean.TryParse("$", out flag);       Console.WriteLine("Result = "+val);    } }OutputThis will produce the following output −Result = False

Convert the value of the current DateTime object to UTC in C#

AmitDiwan
Updated on 09-Dec-2019 06:03:43

2K+ Views

To convert the value of the current DateTime object to Coordinated Universal Time (UTC), the code is as follows −Example Live Demousing System; public class Demo {    public static void Main() {       DateTime d = new DateTime(2019, 12, 11, 7, 11, 25);       Console.WriteLine("Date = {0}", d);       DateTime res = d.ToUniversalTime();       Console.WriteLine("String representation = {0}", res);    } }OutputThis will produce the following output −Date = 11/11/2019 7:11:25 AM String representation = 11/11/2019 7:11:25 AMExampleLet us now see another example − Live Demousing System; public class Demo {    public ... Read More

Advertisements