Found 2587 Articles for Csharp

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

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

220 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

87 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

75 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

160 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

94 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

249 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

Find the last node in LinkedList containing the specified value in C#

AmitDiwan
Updated on 11-Dec-2019 10:37:42

155 Views

To find the last node in LinkedList containing the specified value, the code is as follows −Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main() {       LinkedList list = new LinkedList();       list.AddLast(100);       list.AddLast(200);       list.AddLast(300);       list.AddLast(400);       list.AddLast(500);       list.AddLast(300);       list.AddLast(500);       Console.WriteLine("LinkedList elements...");       foreach(int i in list) {          Console.WriteLine(i);       }       LinkedListNode val = list.FindLast(300);       Console.WriteLine("Specified ... Read More

SortedSet Class in C#

AmitDiwan
Updated on 11-Dec-2019 10:31:56

1K+ Views

The SortedSet class in C# represents a collection of objects that is maintained in sorted order.Following are the properties of the SortedSet class −Sr.NoProperty & Description1ComparerGets the IComparer object that is used to order the values in the SortedSet.2CountGets the number of elements in the SortedSet.3MaxGets the maximum value in the SortedSet, as defined by the comparer.4MinGets the minimum value in the SortedSet, as defined by the comparer.Following are some of the methods of the SortedSet class −Sr.NoMethod & Description1Add(T)Adds an element to the set and returns a value that indicates if it was successfully added.2Clear()Removes all elements from the ... Read More

Get the TypeCode for value type Int16 in C#

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

124 Views

To get the TypeCode for value type Int16, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main() {       short val1 = 0;       short val2 = Int16.MaxValue;       Console.WriteLine("Value1 = "+val1);       Console.WriteLine("Value2 = "+val2);       Console.WriteLine("HashCode for value1 = "+val1.GetHashCode());       Console.WriteLine("HashCode for value2 = "+val2.GetHashCode());       Console.WriteLine("Are they equal? = "+(val1.Equals(val2)));       TypeCode type1 = val1.GetTypeCode();       TypeCode type2 = val2.GetTypeCode();       Console.WriteLine("TypeCode for val1 = "+type1);     ... Read More

Get the members of the current Type in C#

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

110 Views

To get the members of the current Type, the code is as follows −Example Live Demousing System; using System.Reflection; public class Demo {    public static void Main() {       Type type = typeof(Subject);       try {          FieldInfo fieldInfo = type.GetField("SubName");          MemberInfo[] info = type.GetMembers();          Console.Write("Members = ");          for (int i = 0; i < info.Length; i++)             Console.WriteLine(" {0}", info[i]);          Console.WriteLine("FieldInfo = {0}", fieldInfo);       }       ... Read More

Advertisements