Csharp Articles

Page 174 of 196

MathF.Round() Method in C# with Examples

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

The MathF.Round() method in C# is used to round a value to the nearest integer or to the particular number of fractional digits.SyntaxFollowing is the syntax −public static float Round (float x); public static float Round (float x, int digits); public static float Round (float x, int digits, MidpointRounding mode); public static float Round (float x, MidpointRounding mode);ExampleLet us now see an example to implement the MathF.Round() method −using System; public class Demo {    public static void Main(){       float val1 = 15.20f;       float val2 = 3.10f;       Console.WriteLine("Rounded (val1) = "+MathF.Round(val1)); ...

Read More

Decimal.ToInt16() Method in C#

AmitDiwan
AmitDiwan
Updated on 12-Nov-2019 126 Views

The Decimal.ToInt16() method in C# is used to convert the value of the specified Decimal to the equivalent 16-bit signed integer.SyntaxFollowing is the syntax −public static short ToInt16 (decimal val);Above, Val is the decimal number to convert.ExampleLet us now see an example to implement the Decimal.ToInt16() method −using System; public class Demo {    public static void Main(){       Decimal val1 = -3.578m;       Decimal val2 = 9.352m;       Console.WriteLine("Decimal 1 = "+val1);       Console.WriteLine("Decimal 2 = "+val2);       short res1 = Decimal.ToInt16(val1);       short res2 = Decimal.ToInt16(val2); ...

Read More

Decimal.ToDouble() Method in C#

AmitDiwan
AmitDiwan
Updated on 12-Nov-2019 180 Views

The Decimal.ToDouble() method in C# is used to convert the value of the specified Decimal to the equivalent double-precision floating-point number.SyntaxFollowing is the syntax −public static double ToDouble (decimal val);Above, Val is the decimal number to convert.ExampleLet us now see an example to implement the Decimal.ToDouble() method −using System; public class Demo {    public static void Main(){       Decimal val1 = -0.22m;       Decimal val2 = -0.01m;       Console.WriteLine("Decimal 1 = "+val1);       Console.WriteLine("Decimal 2 = "+val2);       Double res1 = Decimal.ToDouble(val1);       Double res2 = Decimal.ToDouble(val2); ...

Read More

Int16.CompareTo() Method in C#

AmitDiwan
AmitDiwan
Updated on 12-Nov-2019 6K+ Views

The Int16.CompareTo() method in C# is used to compare this instance to a specified object or another Int16 instance and returns an integer that indicates whether the value of this instance is less than, equal to, or greater than the value of the specified object or the other Int16 instance.SyntaxFollowing is the syntax −public int CompareTo (short val); public int CompareTo (object val);Above, in the 1st syntax, the value val is an integer to compare, whereas Val in the 2nd syntax is an object to compare.The return value is less than zero if the current instance is less than the ...

Read More

Char.GetUnicodeCategory(String, Int32) Method with Examples in C#

AmitDiwan
AmitDiwan
Updated on 12-Nov-2019 263 Views

The Char.GetUnicodeCategory(String, Int32) method in C# categorizes the character at the specified position in a specified string into a group identified by one of the UnicodeCategory values.SyntaxFollowing is the syntax −public static System.Globalization.UnicodeCategory GetUnicodeCategory (string str, int index);Above, str is a string, whereas the index is the character position in str.ExampleLet us now see an example to implement the Char.GetUnicodeCategory(String, Int32) method −using System; using System.Globalization; public class Demo {    public static void Main(){       string val = "amit";       UnicodeCategory unicode = Char.GetUnicodeCategory(val, 2);       Console.WriteLine("The value at specific index = "+unicode); ...

Read More

Char.GetNumericValue() Method in C#

AmitDiwan
AmitDiwan
Updated on 12-Nov-2019 651 Views

The Char.GetNumericValue() method in C# is used to convert the specified numeric Unicode character to a double-precision floating-point number.SyntaxFollowing is the syntax −public static double GetNumericValue (char ch);Above, the parameter ch is the Unicode character to convert.ExampleLet us now see an example to implement the Char.GetNumericValue() method −using System; public class Demo {    public static void Main(){       char val = 'm';       bool res;       Console.WriteLine("Hashcode for val = "+val.GetHashCode());       res = val.Equals('m');       Console.WriteLine("Return Value = "+res);       Console.WriteLine("Numeric Value = "+Char.GetNumericValue(val));    } ...

Read More

Char.Equals() Method in C#

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

The Char.Equals() method in C# is used to return a value that indicates whether this instance is equal to a specified object or Char value.SyntaxFollowing is the syntax −public bool Equals (char ob);Above, ob is an object to compare to this instance.ExampleLet us now see an example to implement the Char.Equals() method −using System; public class Demo {    public static void Main(){       char val = 'A';       bool res;       res = val.Equals('A');       Console.WriteLine("Return Value = "+res);    } }OutputThis will produce the following output −Return Value = TrueExampleLet ...

Read More

Decimal.ToByte() Method in C#

AmitDiwan
AmitDiwan
Updated on 12-Nov-2019 292 Views

The Decimal.ToByte() method in C# is used to convert the value of the specified Decimal to the equivalent 8-bit unsigned integer.SyntaxFollowing is the syntax −public static byte ToByte (decimal val);Above, Val is the decimal number to convert.ExampleLet us now see an example to implement the Decimal.ToByte() method −using System; public class Demo {    public static void Main(){       Decimal val1 = 6.59m;       Decimal val2 = 30.12m;       Decimal val3 = 69.34m;       Console.WriteLine("Decimal 1 = "+val1);       Console.WriteLine("Decimal 2 = "+val2);       Console.WriteLine("Decimal 3 = "+val3); ...

Read More

Decimal.Ceiling() Method in C#

AmitDiwan
AmitDiwan
Updated on 12-Nov-2019 434 Views

The Decimal.Ceiling() method in C# is used to return the smallest integral value greater than or equal to the specified decimal number.SyntaxFollowing is the syntax −public static decimal Ceiling (decimal val);Above, Val is the decimal number.ExampleLet us now see an example to implement the Decimal.Ceiling() method −using System; public class Demo {    public static void Main(){       Decimal val1 = 12.85m;       Decimal val2 = 3.45m;       Console.WriteLine("Decimal 1 = "+val1);       Console.WriteLine("Decimal 2 = "+val2);       Console.WriteLine("Ceiling (val1) = "+Decimal.Ceiling(val1));       Console.WriteLine("Ceiling (val2) = "+Decimal.Ceiling(val2));   ...

Read More

Decimal.Add() Method in C#

AmitDiwan
AmitDiwan
Updated on 12-Nov-2019 1K+ Views

The Decimal.Add() method in C# is used to add two specified Decimal values.SyntaxFollowing is the syntax −public static decimal Add (decimal val1, decimal val2);Above, va1 is the first decimal to add, whereas val2 is the second decimal to be added.ExampleLet us now see an example to implement the Decimal.Add() method −using System; public class Demo {    public static void Main(){       Decimal val1 = 3.07m;       Decimal val2 = 4.09m;       Console.WriteLine("Decimal 1 = "+val1);       Console.WriteLine("Decimal 2 = "+val2);       Decimal res = Decimal.Add(val1, val2);       ...

Read More
Showing 1731–1740 of 1,951 articles
« Prev 1 172 173 174 175 176 196 Next »
Advertisements