Csharp Articles

Page 187 of 196

Math.Max() Method in C#

AmitDiwan
AmitDiwan
Updated on 06-Nov-2019 7K+ Views

The Math.Max() method in C# is used to return the larger of two specified numbers. This method works for both the numbers being Double, Decimal, Int16, Int32, etc.SyntaxFollowing is the syntax −public static ulong Max (ulong val1, ulong val2); public static uint Max (uint val1, uint val2); public static ushort Max (ushort val1, ushort val2); public static float Max (float val1, float val2); public static byte Max (byte val1, byte val2); public static long Max (long val1, long val2);ExampleLet us now see an example to implement Math.Max() method −using System; public class Demo {    public static void Main(){   ...

Read More

How to create 4-Tuple or quadruple in C#?

AmitDiwan
AmitDiwan
Updated on 06-Nov-2019 270 Views

The Tuple class represents a 4-tuple, which is called quadruple. A tuple is a data structure that has a sequence of elements.It is used in −Easier access to a data set.Easier manipulation of a data set.To represent a single set of data.To return multiple values from a methodTo pass multiple values to a methodExampleLet us now see an example to implement the 4-tuple in C# −using System; public class Demo {    public static void Main(string[] args) {       Tuple tuple = new Tuple("nathan", "steve", "katie", "tim");       Console.WriteLine("Value (Item1)= " + tuple.Item1);       ...

Read More

How to create 3-Tuple or Triple Tuple in C#?

AmitDiwan
AmitDiwan
Updated on 06-Nov-2019 477 Views

The Tuple class represents a 3-tuple, which is called triple. A tuple is a data structure that has a sequence of elements.It is used in −Easier access to a data set.Easier manipulation of a data set.To represent a single set of data.To return multiple values from a methodTo pass multiple values to a methodExampleLet us now see an example to implement the 3-tuple in C# −using System; public class Demo {    public static void Main(string[] args) {       Tuple tuple = new Tuple(35, "steve", "katie");       Console.WriteLine("Value (Item1)= " + tuple.Item1);       Console.WriteLine("Value ...

Read More

DateTimeOffset.Compare() Method in C#

AmitDiwan
AmitDiwan
Updated on 06-Nov-2019 3K+ Views

The DateTimeOffset.Compare() method in C# is used to compare two DateTimeOffset objects and indicates whether the first is earlier than the second, equal to the second, or later than the second. It returns an integer value, 0 − If val1 is later than val2SyntaxFollowing is the syntax −public static int Compare (DateTimeOffset val1, DateTimeOffset val1);Above, val1 is the 1st object to compare, whereas val2 is the 2nd.ExampleLet us now see an example to implement the DateTimeOffset.Compare() method −using System; public class Demo {    public static void Main() {       DateTimeOffset dateTimeOffset1 = new DateTimeOffset(2019, 09, 09, 8, ...

Read More

DateTimeOffset.AddYears() Method in C#

AmitDiwan
AmitDiwan
Updated on 06-Nov-2019 97 Views

The DateTimeOffset.AddYears() method in C# is used to add a specified number of years to the value of this instance.SyntaxFollowing is the syntax −public DateTimeOffset AddYears (int val);Above, the Val parameter is the years to be added to the offset. To subtract, you need to set negative values.ExampleLet us now see an example to implement the DateTimeOffset.AddYears() method −using System; public class Demo {    public static void Main() {       DateTimeOffset dateTimeOffset = new DateTimeOffset(2019, 06, 09, 8, 20, 10, new TimeSpan(-5, 0, 0));       Console.WriteLine("DateTimeOffset (before adding years) = {0}", dateTimeOffset);       ...

Read More

Dictionary.Values Property in C#

AmitDiwan
AmitDiwan
Updated on 06-Nov-2019 359 Views

The Dictionary.Values property in C# is used to fetch all the values in the Dictionary.SyntaxFollowing is the syntax −public System.Collections.Generic.Dictionary.KeyCollection Values{ get; }ExampleLet us now see an example to implement the Dictionary.Values property −using System; using System.Collections.Generic; public class Demo {    public static void Main(){       Dictionary dict = new Dictionary();       dict.Add("One", "Kagido");       dict.Add("Two", "Ngidi");       dict.Add("Three", "Devillers");       dict.Add("Four", "Smith");       dict.Add("Five", "Warner");       Console.WriteLine("Count of elements = "+dict.Count);       Console.WriteLine("Key/value pairs...");       foreach(KeyValuePair res in dict){   ...

Read More

Dictionary Class in C#

AmitDiwan
AmitDiwan
Updated on 06-Nov-2019 964 Views

Dictionary in C# is a collection of keys and values. It is a generic collection class in the System.Collection.Generics namespace.SyntaxFollowing is the syntax −public class DictionaryAbove, the key parameter is the type of keys in the dictionary, whereas TValue is the type of values.ExampleLet us now create a Dictionary and add some elements −using System; using System.Collections.Generic; public class Demo {    public static void Main(){       Dictionary dict = new Dictionary();       dict.Add("One", "John");       dict.Add("Two", "Tom");       dict.Add("Three", "Jacob");       dict.Add("Four", "Kevin");       dict.Add("Five", "Nathan");   ...

Read More

Convert.ToSByte(String, IFormatProvider) Method in C#

AmitDiwan
AmitDiwan
Updated on 06-Nov-2019 200 Views

The Convert.ToSByte() method in C# converts the specified string representation of a number to an equivalent 8-bit signed integer, using the specified culture-specific formatting information.SyntaxFollowing is the syntax −public static sbyte ToSByte (string val, IFormatProvider provider);Above, the parameter value is a string that contains the number to convert. A provider parameter is an object that supplies culture-specific formatting information.ExampleLet us now see an example to implement the Convert.ToSByte() method −using System; using System.Globalization; public class Demo {    public static void Main(){       CultureInfo cultures = new CultureInfo("en-US");       String str = "-2";       ...

Read More

Convert.ToDouble(String, IFormatProvider) Method in C#

AmitDiwan
AmitDiwan
Updated on 06-Nov-2019 2K+ Views

The Convert.ToDouble() method in C# converts the specified string representation of a number to an equivalent double-precision floating-point number, using the specified culture-specific formatting information.SyntaxFollowing is the syntax −public static double ToDouble (string val, IFormatProvider provider);Above, the value value is a string that contains the number to convert, whereas the provider is an object that supplies culture-specific formatting information.ExampleLet us now see an example to implement the Convert.ToDouble() method −using System; using System.Globalization; public class Demo {    public static void Main(){       String val = "876876, 878";       NumberFormatInfo formatProvider = new NumberFormatInfo();     ...

Read More

DateTime.AddHours() Method in C#

AmitDiwan
AmitDiwan
Updated on 06-Nov-2019 7K+ Views

The DateTime.AddHours() method in C# is used to add the specified number of hours to the value of this instance. This method returns a new DateTime.SyntaxFollowing is the syntax −public DateTime AddHours (double hrs);Above, hrs are the number of hours to be added. The value can be negative to subtract the hours.ExampleLet us now see an example to implement the DateTime.AddHours() methodusing System; public class Demo {    public static void Main(){       DateTime d1 = new DateTime(2019, 11, 2, 9, 0, 10);       DateTime d2 = d1.AddHours(2);       System.Console.WriteLine("Initial DateTime = {0:dd} {0:y}, ...

Read More
Showing 1861–1870 of 1,951 articles
« Prev 1 185 186 187 188 189 196 Next »
Advertisements