Csharp Articles

Page 13 of 196

SortedDictionary.Values Property in C#

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 236 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 −using 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 key-value ...

Read More

Random.Next() Method in C#

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 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 −using System; public class Demo {    public static void Main(){       Random r = new Random();       Console.WriteLine("Random numbers.....");       for (int i = 1; i

Read More

C# Copy() Method

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 524 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.Exampleusing 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

C# BitConverter.ToUInt16() Method

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 432 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 -using 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.FromMinutes() Method in C#

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 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.Exampleusing 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 = "+span1); ...

Read More

C# String Properties

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 913 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 -using 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 to ...

Read More

TimeSpan.FromSeconds() Method in C#

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 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 -using 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

StringBuilder.Chars[] Property in C#

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 149 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 -using 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

TimeSpan.FromTicks() Method in C#

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 420 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 -using 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

Thread.CurrentThread Property in C#

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 314 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 -using 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
Showing 121–130 of 1,951 articles
« Prev 1 11 12 13 14 15 196 Next »
Advertisements