Found 2628 Articles for Csharp

C# String.ToLowerInvariant Method

AmitDiwan
Updated on 03-Dec-2019 12:18:20

835 Views

The String.ToLowerInvariant() method in C# is used to return a copy of this String object converted to lowercase using the casing rules of the invariant culture.SyntaxThe syntax is as follows -public string ToLowerInvariant ();ExampleLet us now see an example - Live Demousing System; using System.Text; public class Demo {    public static void Main(String[] args) {       string str1 = "Pink Floyd";       string str2 = "Ariana";       Console.WriteLine("String 1 = "+str1);       Console.WriteLine("String1 ToLowerInvariant = "+str1.ToLowerInvariant());       Console.WriteLine("String 2 = "+str2);       Console.WriteLine("String2 ToLowerInvariant = "+str2.ToLowerInvariant());     ... Read More

TimeSpan.FromTicks() Method in C#

AmitDiwan
Updated on 03-Dec-2019 12:14:14

281 Views

The TimeSpan.FromTicks() method in C# is used to return a TimeSpan that represents a specified time, where the specification is in units of ticks.SyntaxThe syntax is as follows -public static TimeSpan FromTicks (long val);Above, the parameter val is the number of ticks that represent a time.ExampleLet us now see an example - Live Demousing System; public class Demo {    public static void Main() {       TimeSpan span1 = TimeSpan.FromTicks(18768768);       TimeSpan span2 = new TimeSpan(-9, 45, 50);       TimeSpan span3 = TimeSpan.FromHours(5);       TimeSpan span4 = TimeSpan.FromMilliseconds(10000);       TimeSpan span5 ... Read More

C# Object.GetHashCode() Method with Examples

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

898 Views

The Object.GetHashCode() method in C# is used to serve as the default hash function.Syntaxpublic virtual int GetHashCode ();ExampleLet us now see an 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("Hash Code = "+type1.GetHashCode());       Console.WriteLine("Hash Code = "+type2.GetHashCode());    } }OutputHash Code =30015890 Hash Code =21083178ExampleLet us now see another example:using System; public struct Value {    private int v1;    private int ... Read More

C# IsNullOrWhiteSpace() Method

AmitDiwan
Updated on 03-Dec-2019 12:06:56

164 Views

The IsNullOrWhiteSpace() method in C# is used to indicate whether a specified string is null, empty, or consists only of white-space characters.Syntaxpublic static bool IsNullOrWhiteSpace (string val);Above, the parameter val is the string to test. Let us now see an example −ExampleLet us now see an example: Live Demousing System; public class Demo {    public static void Main() {       string str1 = null;       string str2 = String.Empty;       Console.WriteLine("Is string1 null or whitespace? = "+String.IsNullOrWhiteSpace(str1));       Console.WriteLine("Is string2 null or whitespace? = "+String.IsNullOrWhiteSpace(str2));    } }OutputThis will produce the following ... Read More

C# BitConverter.ToUInt16() Method

AmitDiwan
Updated on 03-Dec-2019 12:03:46

238 Views

The BitConverter.ToUInt16() method in C# is used to return a 16-bit unsigned integer converted from two bytes at a specified position in a byte array.Syntaxpublic static ushort ToUInt16 (byte[] val, int begnIndex);Above, val is the byte array, whereas begnIndex is the beginning position within val.ExampleLet us now see an example - Live Demousing System; public class Demo {    public static void Main() {       byte[] arr = { 10, 20, 30, 40, 50};       int count = arr.Length;       Console.Write("Byte Array... ");       for (int i = 0; i < count; i++) ... Read More

TimeSpan.FromSeconds() Method in C#

AmitDiwan
Updated on 03-Dec-2019 11:57:05

4K+ Views

The TimeSpan.FromSeconds() method in C# is used to return a TimeSpan that represents a specified number of seconds, where the specification is accurate to the nearest millisecond.SyntaxThe syntax is as follows -public static TimeSpan FromSeconds (double val);Above, the parameter val is the number of seconds, accurate to the nearest millisecond.ExampleLet us now see an example - Live Demousing System; public class Demo {    public static void Main() {       TimeSpan span1 = TimeSpan.FromSeconds(0.6768788);       TimeSpan span2 = new TimeSpan(25, 15, 45);       TimeSpan span3 = TimeSpan.FromHours(.4788);       TimeSpan span4 = TimeSpan.FromMilliseconds(0.8787);   ... Read More

TimeSpan.FromMinutes() Method in C#

AmitDiwan
Updated on 03-Dec-2019 11:51:18

2K+ Views

The TimeSpan.FromMinutes() method in C# is used to return a TimeSpan that represents a specified number of minutes, where the specification is accurate to the nearest millisecond.Syntaxpublic static TimeSpan FromMinutes (double val);Above, the value val is the number of minutes, accurate to the nearest millisecond.Example Live Demousing System; public class Demo {    public static void Main() {       TimeSpan span1 = TimeSpan.FromHours(0.78787);       TimeSpan span2 = new TimeSpan(10, 30, 40);       TimeSpan span3 = TimeSpan.FromHours(5);       TimeSpan span4 = TimeSpan.FromMilliseconds(1);       TimeSpan span5 = TimeSpan.FromMinutes(100);       Console.WriteLine("TimeSpan1 = ... Read More

C# String.Contains() Method

AmitDiwan
Updated on 03-Dec-2019 11:38:59

8K+ Views

The String.Contains() method in C# is used to return a value indicating whether a specified substring occurs within this string.Syntaxpublic bool Contains (string val);Above, val is the string to search for.Example Live Demousing System; public class Demo {    public static void Main(String[] args) {       string str1 = "Akon";       string str2 = "Ak";       Console.WriteLine("String 1 = "+str1);       Console.WriteLine("HashCode of String 1 = "+str1.GetHashCode());       Console.WriteLine("String 2 = "+str2);       Console.WriteLine("HashCode of String 2 = "+str2.GetHashCode());       Console.WriteLine("String 1 is equal to String 2: ... Read More

C# String Concat with examples

AmitDiwan
Updated on 03-Dec-2019 11:29:25

571 Views

To concat strings in C#, use the String.Concat() method.Syntaxpublic static string Concat (string str1, string str2);Above, the parameters str1 and str2 are the strings to be concatenated.Example Live Demousing System; public class Demo {    public static void Main(String[] args) {       string str1 = "Jack";       string str2 = "Sparrow";       Console.WriteLine("String 1 = "+str1);       Console.WriteLine("HashCode of String 1 = "+str1.GetHashCode());       Console.WriteLine("Does String1 begins with E? = "+str1.StartsWith("E"));       Console.WriteLine("String 2 = "+str2);       Console.WriteLine("HashCode of String 2 = "+str2.GetHashCode());       Console.WriteLine("Does ... Read More

C# StartsWith() Method

AmitDiwan
Updated on 03-Dec-2019 10:42:11

793 Views

The StartsWith() method in C# is used to determine whether the beginning of this string instance matches the specified string.Syntaxpublic bool StartsWith (string val);Above, val is the string to compare.Example Live Demousing System; public class Demo {    public static void Main() {       string str = "JohnAndJacob";       Console.WriteLine("String = "+str);       Console.WriteLine("Does String begins with J? = "+str.StartsWith("J"));       char[] destArr = new char[20];       str.CopyTo(1, destArr, 0, 4);       Console.Write(destArr);    } }OutputThis will produce the following output -String = JohnAndJacob Does String begins with J? = True ohnAExampleLet us now see another example ... Read More

Advertisements