Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Csharp Articles
Page 11 of 196
Stack.Clone() Method in C#
The Stack.Clone() method in C# is used to create a shallow copy of the Stack.SyntaxThe syntax is as follows −public virtual object Clone ();ExampleLet us now see an example −using System; using System.Collections; public class Demo { public static void Main(){ Stack stack = new Stack(); stack.Push(150); stack.Push(300); stack.Push(500); stack.Push(750); stack.Push(1000); stack.Push(1250); stack.Push(1500); stack.Push(2000); stack.Push(2500); Console.WriteLine("Stack elements..."); foreach(int val in stack){ ...
Read MoreQueue.ToArray Method in C#
The Queue.ToArray() method in C# copies the Queue elements to a new array.SyntaxThe syntax is as follows −public virtual object[] ToArray ();ExampleLet us now see an example −using System; using System.Collections.Generic; public class Demo { public static void Main(){ Queue queue = new Queue(); queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); queue.Enqueue(4); queue.Enqueue(5); Console.WriteLine("Queue..."); foreach(int i in queue){ Console.WriteLine(i); } int[] intArr = queue.ToArray(); Console.WriteLine("Convert Queue ...
Read MoreQueue.Synchronized() Method in C#
The Queue.Synchronized() method in C# is used to return a new Queue that wraps the original queue and is thread-safe.SyntaxThe syntax is as follows −public static System.Collections.Queue Synchronized (System.Collections.Queue queue);Above, the parameter queue is the queue to synchronize.ExampleLet us now see an example −using System; using System.Collections; public class Demo { public static void Main(){ Queue queue = new Queue(); queue.Enqueue("AB"); queue.Enqueue("BC"); queue.Enqueue("CD"); queue.Enqueue("DE"); queue.Enqueue("EF"); queue.Enqueue("FG"); queue.Enqueue("GH"); queue.Enqueue("HI"); Console.WriteLine("Queue..."); ...
Read MoreBitConverter.ToInt16() Method in C#
The BitConverter.ToInt16() method in C# is used to return a 16-bit signed integer converted from two bytes at a specified position in a byte array.SyntaxThe syntax is as follows −public static short ToInt16 (byte[] val, int begnIndex);Above, val is the byte array, whereas begnIndex is the beginning position within val.ExampleLet us now see an example −using System; public class Demo { public static void Main(){ byte[] arr = { 0, 0, 7, 10, 18, 20, 25, 26, 32}; Console.WriteLine("Byte Array = {0} ", BitConverter.ToString(arr)); for (int i = 1; i ...
Read MoreStack.CopyTo() Method in C#
The Stack.CopyTo() method in C# is used to copy the Stack to an existing one-dimensional Array, beginning at the specified array index.SyntaxThe syntax is as follows −public virtual void CopyTo (Array arr, int index);Above, the parameter arr is the one-dimensional Array that is the destination of the elements copied from Stack, whereas the index is the index at which the copy initiates.ExampleLet us now see an example −using System; using System.Collections; public class Demo { public static void Main(){ Stack stack = new Stack(); stack.Push(150); stack.Push(300); stack.Push(500); ...
Read MoreSortedDictionary.Count Property in C#
The SortedDictionary.Count property in C# is used to get the number of key/value pairs contained in the SortedDictionary.SyntaxThe syntax is as follows −public int Count { get; }ExampleLet us now see an example −using System; using System.Collections; using System.Collections.Generic; public class Demo { public static void Main(){ SortedDictionary sortedDict = new SortedDictionary(); sortedDict.Add(100, "Mobile"); sortedDict.Add(200, "Laptop"); sortedDict.Add(300, "Desktop"); sortedDict.Add(400, "Speakers"); sortedDict.Add(500, "Headphone"); sortedDict.Add(600, "Earphone"); Console.WriteLine("SortedDictionary key-value pairs..."); IDictionaryEnumerator demoEnum = sortedDict.GetEnumerator(); ...
Read MoreBitConverter.ToDouble() Method in C#
The BitConverter.ToDouble() method in C# is used to return a double-precision floating-point number converted from eight bytes at a specified position in a byte array.SynchronizedThe syntax is as follows −public static double ToDouble (byte[] val, int begnIndex);Above, val is the byte array, whereas begnIndex is the beginning position within val.ExampleLet us now see an example −using System; public class Demo { public static void Main(){ byte[] arr = { 0, 2, 5, 10, 20, 26, 34, 42, 50, 58, 66, 74, 82, 89, 97, 107, 115}; Console.WriteLine("Byte Array = {0} ", BitConverter.ToString(arr)); ...
Read MoreSortedDictionary.Item[] Property in C#
The SortedDictionary.Item[] property in C# is used to get or set the value associated with the specified key.SyntaxThe syntax is as follows −public TValue this[TKey k] { get; set; }Above, the value k is the key of the value to get or set.ExampleLet us now see an example −using System; using System.Collections; using System.Collections.Generic; public class Demo { public static void Main(){ SortedDictionary sortedDict = new SortedDictionary(); sortedDict.Add(1, "One"); sortedDict.Add(2, "Two"); sortedDict.Add(3, "Three"); sortedDict.Add(4, "Four"); sortedDict.Add(5, "Five"); sortedDict.Add(6, ...
Read MoreSingle.ToString Method in C#
The Single.ToString() method in C# is used to convert the numeric value of this instance to its equivalent string representation.SyntaxThe syntax is as follows −public override string ToString ();ExampleLet us now see an example −using System; public class Demo { public static void Main(){ float f1 = 10.0f/0.0f; float f2 = -3.0f; Console.WriteLine("Value1 (String representation) = "+f1.ToString()); Console.WriteLine("Hashcode for Value1 = "+f1.GetHashCode()); Console.WriteLine("TypeCode for Value1 = "+f1.GetTypeCode()); Console.WriteLine("Is Value1 value is positive or negative infinity? = "+Single.IsInfinity(f1)); Console.WriteLine("Is ...
Read MoreSingle.CompareTo() Method in C# with Examples
The Single.CompareTo() method in C# is used to compare this instance to a specified object or to another Single instance and returns an integer that indicates whether the value of this instance is less than, equal to, or greater than the value of the specified object or the other Single instance.The return value is less than zero if the 1st instance is less than 2nd. The return value is 0 if both are equal and greater than zero is 0, if the 1st instance is more than 2nd.SynchronizedThe syntaxes are as follows −public int CompareTo (float val); public int CompareTo ...
Read More