Found 26504 Articles for Server Side Programming

Get the HashCode for the current UInt32 instance in C#

AmitDiwan
Updated on 11-Dec-2019 11:32:46

128 Views

To get the HashCode for the current UInt32 instance, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main() {       uint val1 = 100;       uint val2 = UInt16.MinValue;       Console.WriteLine("HashCode for val1 = "+val1.GetHashCode());       Console.WriteLine("HashCode for val2 = "+val2.GetHashCode());    } }OutputThis will produce the following output −HashCode for val1 = 100 HashCode for val2 = 0ExampleLet us see another example − Live Demousing System; public class Demo {    public static void Main() {       uint val1 = 50;   ... Read More

Using foreach loop in arrays in C#

AmitDiwan
Updated on 11-Dec-2019 11:30:45

247 Views

Let us see an example to use foreach loop in arrays −Example Live Demousing System; public class Demo {    public static void Main() {       string[] products = new string[] { "Electronics", "Accessories", "Clothing", "Toys", "Clothing", "Furniture" };       Console.WriteLine("Products list...");       foreach(string s in products) {          Console.WriteLine(s);       }       Console.WriteLine("Is the products Accessories in the array? = {0}", Array.Exists(products, ele => ele == "Accessories"));       Console.WriteLine("Is the products Stationery in the array? = {0}", Array.Exists(products, ele => ele == "Stationery"));     ... Read More

Get the angle whose sine is float value argument in C#

AmitDiwan
Updated on 11-Dec-2019 11:26:30

153 Views

To get the angle whose sine is float value argument, the code is as follows −Exampleusing System; public class Demo {    public static void Main() {       float val1 = 0.1f;       float val2 = 8.9f;       Console.WriteLine("Angle (val1) = "+(MathF.Asin(val1)));       Console.WriteLine("Angle (val2) = "+(MathF.Asin(val2)));    } }OutputThis will produce the following output −Angle (val1) = 0.1001674 Angle (val2) = NaNExampleLet us see another example −using System; public class Demo {    public static void Main() {       float val1 = 1.2f;       float val2 = ... Read More

Get the hyperbolic arc-cosine of a floating-point value in C#

AmitDiwan
Updated on 11-Dec-2019 11:10:22

130 Views

To get the hyperbolic arc-cosine of a floating-point value, the code is as follows −Exampleusing System; public class Demo {    public static void Main() {       float val1 = 0.1f;       float val2 = 0.9f;       Console.WriteLine("Angle (val1) = "+(MathF.Acosh(val1)));                                 Console.WriteLine("Angle (val2) = "+(MathF.Acosh(val2)));    } }OutputThis will produce the following output −Angle (val1) = NaN Angle (val2) = NaNExampleLet us see another example −using System; public class Demo {    public static void Main() {       float val1 = 5.1f;       float val2 = 8.9f;       Console.WriteLine("Angle (val1) = "+(MathF.Acosh(val1)));       Console.WriteLine("Angle (val2) = "+(MathF.Acosh(val2)));    } }OutputThis will produce the following output −Angle (val1) = 2.312634 Angle (val2) = 2.876027

Check whether the specified character has a surrogate code in C#

AmitDiwan
Updated on 11-Dec-2019 11:07:06

222 Views

To check whether the specified character has a surrogate code, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main() {       string str = new String(new char[] { 'k', 'm', 'g', 't', '\uD800' });       bool res = Char.IsSurrogate(str, 4);       if (res)          Console.WriteLine("Contains Surrogate value!");       else          Console.WriteLine("Does not contain Surrogate value!");    } }OutputThis will produce the following output −Contains Surrogate value!ExampleLet us see another example − Live Demousing System; public class Demo {   ... Read More

How to get Synchronize access to the StringDictionary in C#

AmitDiwan
Updated on 11-Dec-2019 11:02:44

92 Views

To get synchronize access to the StringDictionary, the code is as follows −Example Live Demousing System; using System.Collections; 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("StringDictionary key-value pairs...");       foreach(DictionaryEntry de in strDict) {          Console.WriteLine(de.Key + " " + de.Value);       }       Console.WriteLine("Value ... Read More

How to get Synchronize access to the StringCollection in C#

AmitDiwan
Updated on 11-Dec-2019 10:57:21

76 Views

To get synchronize access to 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 now = "+stringCol.Count); ... Read More

Get the types nested within the current Type C#

AmitDiwan
Updated on 11-Dec-2019 10:54:09

163 Views

To get the types nested within the current Type, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main() {       Type type1 = typeof(Subject);       try {          Type[] type2 = type1.GetNestedTypes();          Console.WriteLine("Nested Types...");          for (int i = 0; i < type2.Length; i++)             Console.WriteLine("{0} ", type2[i]);       }       catch (ArgumentNullException e) {          Console.Write("{0}", e.GetType(), e.Message);       }    } } ... Read More

Get a specific type nested within the current Type in C#

AmitDiwan
Updated on 11-Dec-2019 10:49:41

98 Views

To get a specific type nested within the current Type, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main() {       Type type1 = typeof(Subject);       try {          Type type2 = type1.GetNestedType("AdvSubject");          Console.Write("NestedType = "+ type2);       }       catch (ArgumentNullException e) {          Console.Write("{0}", e.GetType(), e.Message);       }    } } public class Subject {    public class BasicSubject {       //    }    public class AdvSubject ... Read More

Finding the index of first element in the array in C#

AmitDiwan
Updated on 11-Dec-2019 10:44:25

253 Views

To find the index of first element in the array, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main() {       string[] products = new string[] { "Andy", "Mark", "Gary", "Andre"};       Console.WriteLine("One or more name begin with 'A'? = {0}",       Array.Exists(products, ele => ele.StartsWith("A")));       Console.WriteLine("Is the array having fixed size? = " + products.IsFixedSize);       Console.WriteLine("Is the array read only? = " + products.IsReadOnly);       Console.WriteLine("Is the array synchronized? = " + products.IsSynchronized);       Console.WriteLine("Index ... Read More

Advertisements