Check Common Elements in HashSet and Collection in C#

AmitDiwan
Updated on 04-Dec-2019 05:20:15

140 Views

To check if a HashSet and a specified collection share a common element, the C# code is as follows −Example Live Demousing 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 More

BitConverter Class in C#

AmitDiwan
Updated on 04-Dec-2019 05:13:35

1K+ Views

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 More

Queue Contains Method in C#

AmitDiwan
Updated on 03-Dec-2019 13:19:23

215 Views

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 - Live Demousing 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 ... Read More

StringBuilder CopyTo Method in C#

AmitDiwan
Updated on 03-Dec-2019 13:10:16

324 Views

The StringBuilder.CopyTo() method in C# is used to copy the characters from a specified segment of this instance to a specified segment of a destination Char array.SyntaxThe syntax is as follows -public void CopyTo (int sourceIndex, char[] dest, int destIndex, int count);Above, the parameter sourceIndex is the starting position in this instance where characters will be copied from. The dest is the array where characters will be copied, whereas the destIndex is the starting position in destination where characters will be copied. The count parameter is the number of characters to be copied.ExampleLet us now see an example - Live Demousing ... Read More

Clone Method in C# Queue

AmitDiwan
Updated on 03-Dec-2019 13:06:32

308 Views

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 - Live Demousing 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 More

Queue Clear Method in C#

AmitDiwan
Updated on 03-Dec-2019 13:01:58

240 Views

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 - Live Demousing 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 ... Read More

Double IsPositiveInfinity Method in C#

AmitDiwan
Updated on 03-Dec-2019 12:57:10

198 Views

The Double.IsPositiveInfinity() method in C# is used to return a value indicating whether the specified number evaluates to positive infinity.SyntaxThe syntax is as follows -public static bool IsPositiveInfinity (double val);Above, val is a double-precision floating-point number.ExampleLet us now see an example - Live Demousing System; public class Demo {    public static void Main() {       double d = 1.0/0.0;       Console.WriteLine("Double Value = "+d);       Console.WriteLine("HashCode of Double Value = "+d.GetHashCode());       TypeCode type = d.GetTypeCode();       Console.WriteLine("TypeCode of Double Value = "+type);       Console.WriteLine("Positive Infinity? = "+Double.IsInfinity(d)); ... Read More

StringBuilder Chars Property in C#

AmitDiwan
Updated on 03-Dec-2019 12:49:09

122 Views

The StringBuilder.Chars[] property gets or sets the character at the specified character position in this instance.SyntaxThe syntax is as follows -public char this[int index] { get; set; }Above, the index parameter is the position of the character.ExampleLet us now see an example - Live Demousing System; using System.Text; public class Demo {    public static void Main() {       StringBuilder strBuilder = new StringBuilder("ghgh78hkjj");       int num = 0;       for (int i = 0; i < strBuilder.Length; i++) {          char c = strBuilder[i];          if (Char.IsDigit(c))   ... Read More

Thread CurrentThread Property in C#

AmitDiwan
Updated on 03-Dec-2019 12:45:33

278 Views

The Thread.CurrentThread propertyin C# is used to get the currently running thread.SyntaxThe syntax is as follows -public static System.Threading.Thread CurrentThread { get; }ExampleLet us now see an example - Live Demousing System; using System.Threading; public class Demo {    public static void Main() {       Thread thread = new Thread(new ThreadStart(demo1));       ThreadPool.QueueUserWorkItem(new WaitCallback(demo2));       thread = Thread.CurrentThread;       thread.Name ="Demo Thread";       Console.WriteLine("Current running Thread = "+thread.Name);       Console.WriteLine("Current state of Thread = "+thread.ThreadState);       Console.WriteLine("ManagedThreadId = "+thread.ManagedThreadId);    }    public static void demo1() { ... Read More

C# String Properties

AmitDiwan
Updated on 03-Dec-2019 12:40:51

882 Views

Following are the properties of the String class in C# −Sr.NoProperty & Description1CharsGets the Char object at a specified position in the current String object.2LengthGets the number of characters in the current String object.ExampleLet us see an example - Live Demousing System; public class Demo {    public static void Main() {       string str1 = "h8b9";       string str2 = "abcdef";       Console.WriteLine("Is string1 null or empty? = "+string.IsNullOrEmpty(str1));       Console.WriteLine("Is string2 null or empty? = "+string.IsNullOrEmpty(str2));       bool val = str1 != str2;       Console.WriteLine("Is str1 equal ... Read More

Advertisements