Found 2628 Articles for Csharp

Dictionary.Clear Method in C#

AmitDiwan
Updated on 04-Nov-2019 09:57:21

2K+ Views

The Dictionary.Clear() method in C# removes all key/value pairs from the Dictionary.Syntaxpublic void Clear();Let us now see an example to implement the Dictionary.Clear() method −Exampleusing System; using System.Collections.Generic; public class Demo {    public static void Main(){       Dictionary dict =       new Dictionary();       dict.Add("One", "John");       dict.Add("Two", "Tom");       dict.Add("Three", "Jacob");       dict.Add("Four", "Kevin");       dict.Add("Five", "Nathan");       Console.WriteLine("Count of elements = "+dict.Count);       Console.WriteLine("Key/value pairs...");       foreach(KeyValuePair res in dict){          Console.WriteLine("Key = {0}, ... Read More

CharEnumerator.Dispose() Method in C#

AmitDiwan
Updated on 04-Nov-2019 09:53:38

68 Views

The CharEnumerator.Dispose() method in C# is used to release all resources used by the current instance of the CharEnumerator class.Syntaxpublic void Dispose ();Let us now see an example to implement the CharEnumerator.Dispose() method −Exampleusing System; public class Demo {    public static void Main(){       string strNum = "356";       CharEnumerator ch = strNum.GetEnumerator();       while (ch.MoveNext())          Console.Write(ch.Current + " ");       // disposed       ch.Dispose();       // this will show an error since we disposed the object above       // Console.WriteLine(ch.Current);    } }OutputThis will produce the following output −3 5 6

CharEnumerator.Clone() Method in C#

AmitDiwan
Updated on 04-Nov-2019 09:51:58

46 Views

The CharEnumerator.Clone() method in C# is used to create a copy of the current CharEnumerator object.Syntaxpublic object Clone();Let us now see an example to implement the CharEnumerator.Clone() method −Exampleusing System; public class Demo {    public static void Main(){       string strNum = "356";       CharEnumerator ch = strNum.GetEnumerator();       while (ch.MoveNext()){          Console.Write(ch.Current + " ");          CharEnumerator enumClone = (CharEnumerator)ch.Clone();          while (enumClone.MoveNext())             Console.Write(enumClone.Current + " ");          Console.WriteLine();       }    } }OutputThis will produce the following output −3 5 6 5 6 6

Array.Clear() Method in C#

AmitDiwan
Updated on 04-Nov-2019 09:50:00

260 Views

The Array.Clear() method in C# is used to clear the elements in an array and set them to its default. The elements are cleared in a range. The syntax is as follows −Syntaxpublic static void Clear (Array arr, int index, int len);Here, arr is the array whose elements are to be cleared, the index is the beginning index of the elements to clear, and len is the count of elements to clear.Let us now see an example to implement the Array.Clear() method −Exampleusing System; public class Demo{    public static void Main(){       Console.WriteLine("Array elements...");       ... Read More

Array.AsReadOnly(T[]) Method in C#

AmitDiwan
Updated on 04-Nov-2019 08:16:34

148 Views

The Array.AsReadOnly(T[]) method in C# returns a read-only wrapper for the specified array, which is the read-only ReadOnlyCollection.Syntaxpublic static System.Collections.ObjectModel.ReadOnlyCollection AsReadOnly (T[] array);Here, T is the type of the elements of the array, whereas array T[] is the one-dimensional zero-based array.Let us now see an example to implement the Array.AsReadOnly(T[]) method −Exampleusing System; using System.Collections.Generic; public class Demo {    public static void Main() {       String[] arr = { "John", "Tom", "Katie", "Brad" };       // read-only IList wrapper       IList list = Array.AsReadOnly( arr );       // Display the values ... Read More

Char.IsUpper() Method in C#

AmitDiwan
Updated on 04-Nov-2019 08:14:09

1K+ Views

The Char.IsUpper() method in C# indicates whether the specified Unicode character is categorized as an uppercase letter.Syntaxpublic static bool IsUpper (char ch);Above, the parameter ch is the Unicode character to evaluate.Let us now see an example to implement the Char.IsUpper() method −Exampleusing System; public class Demo {    public static void Main(){       bool res;       char val = 'H';       Console.WriteLine("Value = "+val);       res = Char.IsUpper(val);       Console.WriteLine("Is the value an uppercae letter? = "+res);    } }OutputThis will produce the following output −Value = H Is the ... Read More

Char.IsSymbol() Method in C#

AmitDiwan
Updated on 04-Nov-2019 08:10:17

301 Views

The Char.IsSymbol() method in C# is indicating whether the character at the specified position in a specified string is categorized as a symbol character.Syntaxpublic static bool IsSymbol (string str, int index);Above, str is a string, whereas the position of the character to evaluate in str.Let us now see an example to implement the Char.IsSymbol() method −Exampleusing System; public class Demo {    public static void Main(){       bool res;       char val = 'P';       Console.WriteLine("Value = "+val);       res = Char.IsSymbol(val);       Console.WriteLine("Is the value a symbol? = "+res); ... Read More

Char.IsControl(String, Int32) Method in C#

AmitDiwan
Updated on 04-Nov-2019 08:06:22

335 Views

The Char.IsControl(String, Int32) method in C# is used to indicate whether the character at the specified position in a specified string is categorized as a control character.Syntaxpublic static bool IsControl (string str, int index);Above, str is a string. The index parameter is the position of the character to evaluate in str.Let us now see an example to implement the Char.IsControl(String, Int32) method −Exampleusing System; using System.Globalization; public class Demo {    public static void Main(){       string val = "hjk9878hj";       Console.WriteLine("String = "+val);       UnicodeCategory unicode = Char.GetUnicodeCategory(val, 4);       Console.WriteLine("The ... Read More

Array.ConstrainedCopy() Method in C#

AmitDiwan
Updated on 04-Nov-2019 08:01:39

195 Views

The Array.ConstrainedCopy() method in C# is used to copy a range of elements from an Array starting at the specified source index and pastes them to another Array starting at the specified destination index.Syntaxpublic static void ConstrainedCopy (Array sourceArr, int sourceIndex, Array destinationArr, int destinationIndex, int length);Here, sourceArr − The Array that contains the data to copy.sourceIndex − A 32-bit integer that represents the index in the sourceArr at which copying begins.destinationArr − The Array that receives the data.destinationIndex − A 32-bit integer that represents the index in the destinationArr at which storing begins.len − A 32-bit integer that represents ... Read More

Dictionary.ContainsValue() Method in C#

AmitDiwan
Updated on 04-Nov-2019 07:59:08

3K+ Views

The Dictionary.ContainsValue() method in C# is used to check whether the Dictionary contains a specific value or not.Syntaxpublic bool ContainsValue (TValue val);Above, Val is the value to be searched.Let us now see an example to implement the Dictionary.ContainsValue() method −Exampleusing System; using System.Collections.Generic; public class Demo {    public static void Main(){       Dictionary dict =       new Dictionary();       dict.Add("One", "John");       dict.Add("Two", "Tom");       dict.Add("Three", "Jacob");       dict.Add("Four", "Kevin");       dict.Add("Five", "Nathan");       Console.WriteLine("Count of elements = "+dict.Count);       Console.WriteLine("Key/value ... Read More

Advertisements