Csharp Articles

Page 9 of 196

C# BitConverter.ToString(Byte[]) Method

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 2K+ Views

The BitConverter.ToString() method in C# is used to convert the numeric value of each element of a specified array of bytes to its equivalent hexadecimal string representation.Syntaxpublic static string ToString (byte[] val);Above, val is the byte array.Exampleusing System; public class Demo {    public static void Main() {       byte[] arr = {0, 10, 2, 5, 32, 45};       int count = arr.Length;       Console.Write("Byte Array... ");       for (int i = 0; i < count; i++) {          Console.Write(""+arr[i]);       }       Console.WriteLine("Byte Array ...

Read More

C# Object.GetType() Method with Examples

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 3K+ Views

The Object.GetTypeCode() method in C# is used to get the Type of the current instance.SyntaxThe syntax is as follows −public Type GetType ();Exampleusing System; public class Demo {    public static void Main() {       Object ob = new Object();       String str = "Jim";       Type type1 = ob.GetType();       Type type2 = str.GetType();       Console.WriteLine("Type = "+type1);       Console.WriteLine("Type = "+type2);       Console.WriteLine("Hash Code = "+type1.GetHashCode());       Console.WriteLine("Hash Code = "+type2.GetHashCode());    } }OutputType = System.Object Type = System.String Hash Code = 30015890 Hash Code = 21083178Exampleusing System; public struct ...

Read More

C# Queue.TrimExcess() Method with Examples

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 355 Views

The Queue.TrimExcess() method in C# is used to set the capacity to the actual number of elements in the Queue, if that number is less than 90 percent of current capacity.Syntaxpublic void TrimExcess ();Exampleusing 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...");   ...

Read More

C# String Operators

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 628 Views

There are two string operators in C#: Equality and Inequality.ExampleLet us see an example of Equality operator −using System; public class Demo {    public static void Main() {       string str1 = "Amit";       string str2 = " ";       Console.WriteLine("Is string1 null or empty? = "+string.IsNullOrEmpty(str1));       Console.WriteLine("Is string2 null or empty? = "+string.IsNullOrEmpty(str2));       Console.WriteLine("Is string1 equal to str2? = "+str1 == str2);    } }OutputIs string1 null or empty? = False Is string2 null or empty? = False FalseExampleLet us now see an example of C# Inequality operator −using System; public class Demo {    public static void ...

Read More

C# BitConverter.ToUInt32() Method

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 417 Views

The BitConverter.ToUInt32() method in C# is used to return a 32-bit unsigned integer converted from four bytes at a specified position in a byte array.Syntaxpublic static uint ToUInt32 (byte[] val, int begnIndex);Above, val is the byte array, whereas begnIndex is the starting position withing val.Exampleusing System; public class Demo {    public static void Main() {       byte[] arr = { 0, 3, 5, 10, 15, 2};       int count = arr.Length;       Console.Write("Byte Array... ");       for (int i = 0; i < count; i++) {          Console.Write(""+arr[i]); ...

Read More

C# BitConverter.ToUInt64 Method

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 343 Views

The BitConverter.ToUInt64() method in C# is used to return a 64-bit unsigned integer converted from eight bytes at a specified position in a byte array.Syntaxpublic static ulong ToUInt64 (byte[] val, int begnIndex);ExampleAbove, val is the byte array, whereas begnIndex is the beginning position within val.using System; public class Demo {    public static void Main() {       byte[] arr = { 0, 0, 1, 3, 5, 7, 9, 11, 15 };       int count = arr.Length;       Console.Write("Byte Array... ");       for (int i = 0; i < count; i++) {   ...

Read More

TimeSpan.FromDays() Method in C#

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 745 Views

The TimeSpan.FromDays() method in C# is used to return a TimeSpan that represents a specified number of days, where the specification is accurate to the nearest millisecond.SyntaxThe syntax is as follows −public static TimeSpan FromDays (double val);Above, the parameter val is the number of days, accurate to the nearest millisecond.ExampleLet us now see an example −using System; public class Demo {    public static void Main(){       TimeSpan span1 = new TimeSpan(5, 25, 0);       TimeSpan span2 = new TimeSpan(1, 10, 0);       TimeSpan span3 = TimeSpan.FromDays(43.999999);       Console.WriteLine("TimeSpan1 = "+span1);   ...

Read More

Double.IsNaN() Method in C#

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 757 Views

The Double.IsNaN() method in C# is used to return a value that indicates whether the specified value is not a number (NaN).SyntaxThe syntax is as follows −public static bool IsNaN (double val);Above, val is the double-precision floating-point number.ExampleLet us now see an example −using 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

Stack.Equals() Method in C#

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 364 Views

The Stack.Equals() method in C# is used to check whether a Stack class object is equal to another object or not.SyntaxThe syntax is as follows −public virtual bool Equals (object ob);Above, the parameter ob is the object compared with another.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);     ...

Read More

TimeSpan.FromHours() Method in C#

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 1K+ Views

The TimeSpan.FromHours() method in C# is used to return a TimeSpan that represents a specified number of hours, where the specification is accurate to the nearest millisecond.SyntaxThe syntax is as follows −public static TimeSpan FromHours (double val);Above, the value val is a number of hours accurate to the nearest millisecond.ExampleLet us now see an example −using System; public class Demo {    public static void Main(){       TimeSpan span1 = TimeSpan.FromDays(0.000323456);       TimeSpan span2 = new TimeSpan(-2, 05, 10);       TimeSpan span3 = TimeSpan.FromHours(5);       Console.WriteLine("TimeSpan1 = "+span1);       Console.WriteLine("TimeSpan2 ...

Read More
Showing 81–90 of 1,951 articles
« Prev 1 7 8 9 10 11 196 Next »
Advertisements