Found 2587 Articles for Csharp

C# Object.GetType() Method with Examples

AmitDiwan
Updated on 10-Jul-2020 05:04:20

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 ();Example Live Demousing 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 = 21083178Example Live Demousing System; ... Read More

C# BitConverter.ToString(Byte[]) Method

AmitDiwan
Updated on 02-Dec-2019 12:16:46

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

Single.Equals() Method in C# with Examples

AmitDiwan
Updated on 02-Dec-2019 12:11:42

93 Views

The Single.Equals() method in C# is used to return a value indicating whether two instances of Single represent the same value.Syntaxpublic bool Equals (float ob); public override bool Equals (object ob);The parameter ob for the both the syntaxes is an object to compare with this instance.Example Live Demousing System; public class Demo {    public static void Main() {       float f1 = 15.9f;       float f2 = 40.2f;       Console.WriteLine("Value1 = "+f1);       Console.WriteLine("Value2 = "+f2);         Console.WriteLine("Are both the values equal? = "+f1.Equals(f2));    } }OutputValue1 = 15.9 Value2 = 40.2 Are both the values equal? = FalseExample Live ... Read More

C# BitConverter.ToChar() Method

AmitDiwan
Updated on 02-Dec-2019 12:07:51

189 Views

The BitConverter.ToChar() method in C# is used to returns a Unicode character converted from two bytes at a specified position in a byte array.Syntaxpublic static char ToChar (byte[] value, int begnIndex);Above, val is the byte array, whereas begnIndex is the beginning position within val.Example Live Demousing System; public class Demo {    public static void Main() {       byte[] arr = { 0, 20, 50, 65 };       Console.WriteLine("Array = {0} ",       BitConverter.ToString(arr));       for (int i = 1; i < arr.Length - 1; i = i + 2) {     ... Read More

Boolean.GetHashCode() Method in C# with Examples

AmitDiwan
Updated on 02-Dec-2019 11:25:31

156 Views

The Boolean.GetHashCode() method in C# is used to return the hash code for this instance.Syntaxpublic override int GetHashCode ();Example Live Demousing System; public class Demo {    public static void Main(String[] args){       string str = "JackSparrow!";       bool val = true;       char[] arr = { 'J', 'a'};       Console.WriteLine("String = "+str);       Console.WriteLine("String (after trim) = " + str.Trim(arr));       Console.WriteLine("String (Hashcode) = "+str.GetHashCode());       Console.WriteLine("Bool (Hashcode) = "+val.GetHashCode());    } }OutputString = JackSparrow! String (after trim) = ckSparrow! String (Hashcode) = -203134198 Bool (Hashcode) = 1Example Live Demousing System; public class Demo {    public static void ... Read More

Uri.HexEscape(Char) Method in C#

AmitDiwan
Updated on 14-Nov-2019 06:57:07

165 Views

The Uri.HexEscape() method in C# is used to convert a specified character into its hexadecimal equivalent.SyntaxFollowing is the syntax −public static string HexEscape (char ch);Above, the parameter ch is the character to convert to hexadecimal representation.ExampleLet us now see an example to implement the Uri.HexEscape() method −using System; public class Demo {    public static void Main(){       char ch = 'k';       string res = Uri.HexEscape(ch);       Console.WriteLine("Hexadecimal Equivalent = "+res);    } }OutputThis will produce the following output −Hexadecimal Equivalent = %6BExampleLet us now see another example to implement the Uri.HexEscape() method ... Read More

UInt32.GetHashCode() Method in C# with Examples

AmitDiwan
Updated on 14-Nov-2019 06:56:00

116 Views

The UInt32.GetHashCode() method in C# is used to get the HashCode for the current UInt32 instance.SyntaxFollowing is the syntax −public override int GetHashCode ();ExampleLet us now see an example to implement the UInt32.GetHashCode() method −using System; public class Demo {    public static void Main(){       uint val1 = 100;       uint val2 = UInt16.MinValue;       Console.WriteLine("HashCode for val1 = "+val1.GetHashCode());       Console.WriteLine("HashCode for val2 = "+val2.GetHashCode());    } }OutputThis will produce the following output −HashCode for val1 = 100 HashCode for val2 = 0ExampleLet us now see another example to implement ... Read More

How to change the WindowWidth of the Console in C#?

AmitDiwan
Updated on 14-Nov-2019 06:53:59

129 Views

Use the Console.WindowWidth Property to change the WindowWidth of the Console.ExampleLet us now see an example −using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Demo {    public static void Main (string[] args) {       Console.InputEncoding = Encoding.ASCII;       Console.WriteLine("Input Encoding Scheme = "+Console.InputEncoding);       Console.OutputEncoding = Encoding.ASCII;       Console.WriteLine("Output Encoding Scheme = "+Console.OutputEncoding);       Console.CursorVisible = false;       Console.Write("Cursor is Visible? "+ Console.CursorVisible);       Console.WindowWidth = 30;       Console.Write("WindowWidth = "+Console.WindowWidth);    } } OutputThis will produce the following ... Read More

How to change the WindowTop of the Console in C#?

AmitDiwan
Updated on 14-Nov-2019 06:52:56

139 Views

Use the Console.WindowTop Property to change the WindowTop of the Console in C#.ExampleLet us now see an example −using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Demo {    public static void Main (string[] args) {       Console.InputEncoding = Encoding.ASCII;       Console.WriteLine("Input Encoding Scheme = "+Console.InputEncoding);       Console.OutputEncoding = Encoding.ASCII;       Console.WriteLine("Output Encoding Scheme = "+Console.OutputEncoding);       Console.CursorVisible = false;       Console.Write("Cursor is Visible? "+ Console.CursorVisible);       Console.WindowTop = 40;       Console.Write("WindowTop = "+Console.WindowTop);    } }OutputThis will produce the following ... Read More

UInt32.Equals() Method in C# with Examples

AmitDiwan
Updated on 14-Nov-2019 06:51:30

143 Views

The UInt32.Equals() method in C# returns a value indicating whether this instance is equal to a specified object or UInt32.SyntaxFollowing is the syntax −public override bool Equals (object ob); public bool Equals (uint ob);Above, the parameter ob for the 1st syntax is an object to compare to this instance and the parameter ob for the 2nd syntax is the 32-bit unsigned integer to compare to this instance.ExampleLet us now see an example to implement the UInt32.Equals() method −using System; public class Demo {    public static void Main(){       uint val1 = 52;       uint val2 ... Read More

Advertisements