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 14 of 196
Queue.Clear Method in C#
The Queue.Clear() method in C# is used to clear all object from Queue.SyntaxThe syntax is as follows -public virtual void Clear ();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(100); queue.Enqueue(200); queue.Enqueue(300); queue.Enqueue(400); queue.Enqueue(500); queue.Enqueue(600); queue.Enqueue(700); queue.Enqueue(800); queue.Enqueue(900); queue.Enqueue(1000); Console.WriteLine("Queue..."); foreach(int i in queue) ...
Read MoreQueue.Clone() Method in C#
The Queue.Clone() method in C# is used to create a shallow copy of the Queue.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(string[] args) { Queue queue = new Queue(); queue.Enqueue("One"); queue.Enqueue("Two"); queue.Enqueue("Three"); queue.Enqueue("Four"); queue.Enqueue("Five"); queue.Enqueue("Six"); queue.Enqueue("Seven"); queue.Enqueue("Eight"); Console.WriteLine("Queue..."); foreach(string str in queue) { ...
Read MoreQueue.Contains() Method in C#
The Queue.Contains() method in C# is used to determine whether an element is in the Queue.SyntaxThe syntax is as follows -public virtual bool Contains (object ob);Above, the parameter ob is the Object to locate in the Queue.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("Gary"); queue.Enqueue("Jack"); queue.Enqueue("Ryan"); queue.Enqueue("Kevin"); queue.Enqueue("Mark"); queue.Enqueue("Jack"); queue.Enqueue("Ryan"); queue.Enqueue("Kevin"); Console.Write("Count of ...
Read MoreBitConverter Class in C#
The BitConverter class converts base data types to an array of bytes, and an array of bytes to base data types.Following are the methods −MethodDescriptionDoubleToInt64Bits(Double)Converts the specified double-precision floating-point number to a 64-bit signed integer.GetBytes(Boolean)Returns the specified Boolean value as a byte array.GetBytes(Char)Returns the specified Unicode character value as an array of bytes.GetBytes(Double)Returns the specified double-precision floating-point value as an array of bytes.GetBytes(Int16)Returns the specified 16-bit signed integer value as an array of bytes.GetBytes(Int32)Returns the specified 32-bit signed integer value as an array of bytes.Int64BitsToDouble(Int64)Reinterprets the specified 64-bit signed integer to a double-precision floating-point number.ToBoolean(Byte[], Int32)Returns a Boolean value converted ...
Read MoreCheck if a value is in LinkedList in C#
To check if a value is in LinkedList, try the below code −Exampleusing System; using System.Collections.Generic; public class Demo { public static void Main(){ LinkedList linkedList = new LinkedList(); linkedList.AddLast(25); linkedList.AddLast(50); linkedList.AddLast(100); linkedList.AddLast(200); linkedList.AddLast(400); linkedList.AddLast(500); linkedList.AddLast(550); linkedList.AddLast(600); linkedList.AddLast(800); linkedList.AddLast(1200); Console.WriteLine("Count of nodes = " + linkedList.Count); foreach(int val in linkedList){ Console.WriteLine(val); } ...
Read MoreCheck if a HashSet and a specified collection share common element in C#
To check if a HashSet and a specified collection share a common element, the C# code is as follows −Exampleusing System; using System.Collections.Generic; public class Demo { public static void Main(){ HashSet set1 = new HashSet(); set1.Add(25); set1.Add(50); set1.Add(75); set1.Add(100); set1.Add(125); set1.Add(150); Console.WriteLine("Elements in HashSet1"); foreach(int val in set1){ Console.WriteLine(val); } HashSet set2 = new HashSet(); set2.Add(30); ...
Read MoreRemoving all nodes from LinkedList in C#
To remove all nodes from LinkedList, the code is as follows −Exampleusing System; using System.Collections.Generic; public class Demo { public static void Main() { int [] num = {10, 20, 30, 40, 50}; LinkedList list = new LinkedList(num); Console.WriteLine("LinkedList nodes..."); foreach (var n in list) { Console.WriteLine(n); } list.Clear(); Console.WriteLine("LinkedList is empty now!"); foreach (var n in list) { Console.WriteLine(n); } } }OutputThis ...
Read MoreCheck if an array contains the elements that match the specified conditions in C#
To check if an array contains the elements that match the specific conditions, we can use the StartsWith() method in C# −Exampleusing System; public class Demo { public static void Main(){ string[] products = { "Electronics", "Accessories", "Clothing", "Toys", "Clothing", "Furniture" }; Console.WriteLine("Products list..."); foreach(string s in products){ Console.WriteLine(s); } Console.WriteLine("One or more products begin with the letter 'C'? = {0}", Array.Exists(products, ele => ele.StartsWith("C"))); Console.WriteLine("One or more planets begin with 'D'? = {0}", ...
Read MoreCheck if an array is read-only or not in C#
To check if an array is read-only or not, try the below code −Exampleusing System; public class Demo { public static void Main(){ string[] products = new string[] { }; Console.WriteLine("One or more planets begin with 'E'? = {0}", Array.Exists(products, ele => ele.StartsWith("E"))); Console.WriteLine("Is the array having fixed size? = " + products.IsFixedSize); Console.WriteLine("Is the array read only? = " + products.IsReadOnly); } }OutputThis will produce the following code −One or more planets begin with 'E'? = False Is the array having ...
Read MoreCheck if an Array has fixed size or not in C#
To check if an array has fixed size or not, try the below code −Exampleusing 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}", ...
Read More