Found 2628 Articles for Csharp

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

AmitDiwan
Updated on 05-Nov-2019 08:15:27

258 Views

The Convert.ToBoolean() method in C# is used to convert a specified value to an equivalent Boolean value.SyntaxFollowing is the syntax −public static bool ToBoolean (string val, IFormatProvider provider);Above, Val is a string that contains the value of either TrueString or FalseString, whereas the provider is an object that supplies culture-specific formatting information.ExampleLet us now see an example to implement the Convert.ToBoolean() method −using System; using System.Globalization; public class Demo {    public static void Main(){       CultureInfo cultures = new CultureInfo("en-US");       String str = "true";       Console.WriteLine("Converted bool value...");       bool ... Read More

DateTime.DaysInMonth() Method in C#

AmitDiwan
Updated on 05-Nov-2019 08:12:53

2K+ Views

The DateTime.DaysInMonth() method in C# is used to return the number of days in the specified month and year. For example, 31 for month value 1 i.e. January.SyntaxFollowing is the syntax −public static int DaysInMonth (int year, int month);ExampleLet us now see an example to implement the DateTime.DaysInMonth() method −using System; public class Demo {    public static void Main() {       DateTime date1 = new DateTime(2019, 08, 20, 6, 20, 40);       DateTime date2 = new DateTime(2019, 06, 20, 6, 20, 40);       Console.WriteLine("DateTime 1 = {0:dd} {0:y}, {0:hh}:{0:mm}:{0:ss} ", date1);     ... Read More

UInt16.MaxValue Field in C# with Examples

AmitDiwan
Updated on 05-Nov-2019 08:10:12

204 Views

The UInt16.MaxValue field in C# represents the maximum value of the 16-bit unsigned integer.SyntaxFollowing is the syntax −public const ushort MaxValue = 65535;ExampleLet us now see an example to implement the UInt16.MaxValue field −using System; public class Demo {    public static void Main(){       ushort val1 = 23;       ushort val2 = 0;       Console.WriteLine("Value1 = "+val1);       Console.WriteLine("Value2 = "+val2);       Console.WriteLine("HashCode for value1 = "+val1.GetHashCode());       Console.WriteLine("HashCode for value2 = "+val2.GetHashCode());       Console.WriteLine("Are they equal? = "+(val1.Equals(val2)));       TypeCode type1 = ... Read More

UInt16.GetTypeCode() Method in C# with Examples

AmitDiwan
Updated on 05-Nov-2019 08:04:27

59 Views

The UInt16.GetTypeCode() method in C# is used to return the TypeCode for value type UInt16.SyntaxFollowing is the syntax −public TypeCode GetTypeCode ();ExampleLet us now see an example to implement the UInt16.GetTypeCode() method −using System; public class Demo {    public static void Main(){       ushort val1 = 55;       ushort val2 = 100;       TypeCode type1 = val1.GetTypeCode();       TypeCode type2 = val2.GetTypeCode();       Console.WriteLine("Typecode for val1 = "+type1);       Console.WriteLine("Typecode for val1 = "+type2);    } }OutputThis will produce the following output −Typecode for val1 = UInt16 ... Read More

UInt16.GetHashCode() Method in C# with Examples

AmitDiwan
Updated on 05-Nov-2019 07:59:29

69 Views

The UInt16.GetHashCode() method in C# is used to get the HashCode for the current UInt16 instance.SyntaxFollowing is the syntax −public override int GetHashCode ();ExampleLet us now see an example to implement the UInt16.GetHashCode() method −using System; public class Demo {    public static void Main(){       ushort val1 = 100;       ushort 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

Tuple Class in C#

AmitDiwan
Updated on 05-Nov-2019 07:57:04

74 Views

The Tuple class represents a 2-tuple, which is called pair. 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 methodIt has two properties −Item1 − Get the value of the current Tuple object's first component.Item2 − Get the value of the current Tuple object's second component.ExampleLet us now see an example to implement the 2-tuple in C# −using System; public class Demo {    public static ... Read More

UInt16.Equals Method in C# with Examples

AmitDiwan
Updated on 05-Nov-2019 07:54:23

68 Views

The UInt16.Equals() method in C# returns a value indicating whether this instance is equal to a specified object or UInt16.SyntaxFollowing is the syntax −public override bool Equals (object ob); public bool Equals (ushort 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 16-bit unsigned integer to compare to this instance.ExampleLet us now see an example to implement the UInt16.Equals() method −using System; public class Demo {    public static void Main(){       ushort val1 = 52;       ushort val2 ... Read More

UInt16.CompareTo() Method in C# with Examples

AmitDiwan
Updated on 05-Nov-2019 07:50:34

139 Views

The UInt16.CompareTo() method in C# is used to compare the current instance to a specified object or UInt16 and returns an indication of their relative values.SyntaxFollowing is the syntax −public int CompareTo (object val); public int CompareTo (ushort val;Above, the value for the 1st syntax is an object to compare. The value for 2nd syntax is an unsigned integer to compare.The return value is 0 if the current instance is equal to value. It’s less than zero if the current instance is less than val. The return value is more than zero if the current instance is greater than the ... Read More

MathF.Truncate() Method in C# with Examples

AmitDiwan
Updated on 05-Nov-2019 07:47:44

308 Views

The MathF.Truncate() method in C# is used to calculate an integral part of a specified single number or single-precision floating-point number.SyntaxFollowing is the syntax −public static float Truncate (float val);Above, Val is the specified number to be truncatedExampleLet us now see an example to implement the MathF.Truncate() method −using System; public class Demo {    public static void Main(){       float val1 = float.PositiveInfinity;       float val2 = float.NegativeInfinity;       Console.WriteLine("MathF.Truncate(val1) = "+MathF.Truncate(val1));       Console.WriteLine("MathF.Truncate(val2) = "+MathF.Truncate(val2));    } }OutputThis will produce the following output −MathF.Truncate(val1) = Infinity MathF.Truncate(val2) = -InfinityExampleLet us ... Read More

MathF.Tanh() Method in C# with Examples

AmitDiwan
Updated on 05-Nov-2019 07:44:22

79 Views

The MathF.Tanh() method in C# returns the hyperbolic tangent of a given single value argument.SyntaxFollowing is the syntax −public static float Tanh (float val);Above, Val is the is number whose hyperbolic tangent is to be returned.ExampleLet us now see an example to implement the MathF.Tanh() method −using System; public class Demo {    public static void Main(){       float val1 = 10f;       float val2 = float.NaN;       Console.WriteLine("MathF.Tanh(val1) = "+MathF.Tanh(val1));       Console.WriteLine("MathF.Tanh(val2) = "+MathF.Tanh(val2));    } }OutputThis will produce the following output −MathF.Tanh(val1) = 1 MathF.Tanh(val2) = NaNExampleLet us now see ... Read More

Advertisements