Found 2587 Articles for Csharp

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# Stack.TrimExcess() Method with Examples

AmitDiwan
Updated on 03-Dec-2019 10:35:34

611 Views

The Stack.TrimExcess() method in C# is used to set the capacity to the actual number of elements in the List, if that number is less than a threshold value.Syntaxpublic void TrimExcess ();Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main() {       Stack stack = new Stack();       stack.Push(100);       stack.Push(150);       stack.Push(175);       stack.Push(200);       stack.Push(225);       stack.Push(250);       stack.Push(300);       stack.Push(400);       stack.Push(450);       stack.Push(500);       Console.WriteLine("Elements in the ... Read More

Array.BinarySearch(Array, Object) Method with examples in C#

AmitDiwan
Updated on 03-Dec-2019 10:27:25

175 Views

The Array.BinarySearch(Array, Object) method in C# is used to search an entire one-dimensional sorted array for a specific element, using the IComparable interface implemented by each element of the array and by the specified object.Syntaxpublic static int BinarySearch (Array arr, object val);Above, arr is the sorted 1-D array, whereas val is the object to search for.Example Live Demousing System; public class Demo {    public static void Main() {       int[] intArr = {5, 10, 15, 20};       Array.Sort(intArr);       Console.WriteLine("Array elements...");       foreach(int i in intArr) {          Console.WriteLine(i); ... Read More

C# Copy() Method

AmitDiwan
Updated on 03-Dec-2019 10:19:27

490 Views

The Copy() method in C# is used to create a new instance of String with the same value as a specified String.Syntaxpublic static string Copy (string s);Above, s is the string to copy.Example Live Demousing System; public class Demo {    public static void Main(string[] args) {       string s1 = "Amy";       string s2 = "Katie";       string s3 = String.Copy(s2);       Console.WriteLine("String1 = "+s1);       Console.WriteLine("String2 = "+s2);       Console.WriteLine("Are both the strings equal? = "+s1.Equals(s2));       Console.WriteLine("Are both the strings equal? = "+s2.Equals(s3));   ... Read More

StringBuilder.ToString() Method in C#

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

2K+ Views

The StringBuilder.ToString() method in C# is used to convert the value of a StringBuilder to a String.SyntaxThe syntax is as follows −public override string ToString (); public string ToString (int begnIndex, int len);Above, the parameter begnIndex is the starting position of the substring in this instance, whereas len is the length of the substring.ExampleLet us now see an example − Live Demousing System; using System.Text; public class Demo{    public static void Main(){       StringBuilder strBuilder = new StringBuilder("Katie");       Console.WriteLine("String = "+strBuilder.ToString());       Console.WriteLine("StringBuilder capacity = "+strBuilder.Capacity);       Console.WriteLine("StringBuilder length = "+strBuilder.Length); ... Read More

Random.Next() Method in C#

AmitDiwan
Updated on 03-Dec-2019 09:54:27

3K+ Views

The Random.Next() method in C# is used to return a non-negative random integer.SyntaxThe syntax is as follows −public virtual int Next (); public virtual int Next (int maxVal);Above, the maxVal parameter is the exclusive upper bound of the random number to be generated.ExampleLet us now see an example − Live Demousing System; public class Demo {    public static void Main(){       Random r = new Random();       Console.WriteLine("Random numbers.....");       for (int i = 1; i

SortedDictionary.Values Property in C#

AmitDiwan
Updated on 03-Dec-2019 09:52:19

171 Views

The SortedDictionary.Value property in C# is used to get a collection containing the values in the SortedDictionary.SyntaxThe syntax is as follows −public System.Collections.Generic.SortedDictionary.ValueCollection Values { get; }ExampleLet us now see an example − Live Demousing System; using System.Collections; using System.Collections.Generic; public class Demo {    public static void Main(){       SortedDictionarysortedDict = new SortedDictionary();       sortedDict.Add(1, "Ultrabook");       sortedDict.Add(2, "Alienware");       sortedDict.Add(3, "Notebook");       sortedDict.Add(4, "Connector");       sortedDict.Add(5, "Flash Drive");       sortedDict.Add(6, "SSD");       sortedDict.Add(7, "HDD");       sortedDict.Add(8, "Earphone");       Console.WriteLine("SortedDictionary ... Read More

Double.IsNegativeInfinity() Method in C#

AmitDiwan
Updated on 03-Dec-2019 09:48:11

63 Views

The Double.IsNegativeInfinity() method in C# is used to return a value indicating whether the specified number evaluates to negative infinity.SyntaxThe syntax is as follows −public static bool IsNegativeInfinity (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 = 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

Boolean.GetTypeCode() Method in C# with Examples

AmitDiwan
Updated on 03-Dec-2019 09:46:18

83 Views

The Boolean.GetTypeCode() method in C# is used to return the type code for the Boolean value type.SyntaxThe syntax is as follows −public TypeCode GetTypeCode ();ExampleLet us now see an 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());       Console.WriteLine("Bool ... Read More

Advertisements