Found 2628 Articles for Csharp

Math.Round() Method in C#

AmitDiwan
Updated on 08-Nov-2019 11:16:22

8K+ Views

The Math.Round() method in C# rounds a value to the nearest integer or to the specified number of fractional digits.MethodsThe following are the methods overloaded by Math.Round() −Math.Round(Double) Math.Round(Double, Int32) Math.Round(Double, Int32, MidpointRounding) Math.Round(Double, MidpointRounding) Math.Round(Decimal) Math.Round(Decimal, Int32) Math.Round(Decimal, Int32, MidpointRounding) Math.Round(Decimal, MidpointRounding)ExampleLet us now see an example to implement Math.Round() method i.e. Math.Round(Decimal) −using System; public class Demo {    public static void Main(){       Decimal val1 = 78.12m;       Decimal val2 = 30.675m;       Console.WriteLine("Decimal Value = " + val1);       Console.WriteLine("Rounded value = " + Math.Round(val1));       ... Read More

Int16.Equals Method in C# with Examples

AmitDiwan
Updated on 08-Nov-2019 11:13:54

88 Views

The Int16.Equals() method in C# is used to return a value indicating whether this instance is equal to a specified object or Int16.SyntaxFollowing is the syntax −public bool Equals (short ob); public override bool Equals (object ob);Above, the parameter ob for the 1st syntax is an Int16 value to compare to this instance.The parameter ob for the 2nd syntax is the object to compare to this instance.ExampleLet us now see an example to implement the Int16.Equals() method −using System; public class Demo {    public static void Main(){       short val1 = 15;       short val2 ... Read More

Array.FindAll() Method in C#

AmitDiwan
Updated on 08-Nov-2019 11:11:00

2K+ Views

The Array.FindAll() method in C# is used to retrieve all the elements that match the conditions defined by the specified predicate.SyntaxFollowing is the syntax −public static T[] FindAll (T[] array, Predicate match);ExampleLet us now see an example to implement the Array.FindAll() method −using System; public class Demo{    public static void Main(){       Console.WriteLine("Array elements...");       string[] arr = { "car", "bike", "truck", "bus"};       for (int i = 0; i < arr.Length; i++){          Console.Write("{0} ", arr[i]);       }       Console.WriteLine();       String[] res ... Read More

Array.Find() Method in C#

AmitDiwan
Updated on 08-Nov-2019 11:09:43

8K+ Views

The Array.Find() method in C# is used to search for an element that matches the conditions defined by the specified predicate and returns the first occurrence within the entire Array.SyntaxFollowing is the syntax −public static T Find (T[] array, Predicate match);Above, the array is the one-dimensional, zero-based array to search, whereas match is the predicate that defines the conditions of the element to search for.ExampleLet us now see an example to implement the Array.Find() method −using System; public class Demo{    public static void Main(){       Console.WriteLine("Array elements...");       string[] arr = { "car", "bike", "truck", ... Read More

DateTime.ToShortDateString() Method in C#

AmitDiwan
Updated on 08-Nov-2019 11:08:13

6K+ Views

The DateTime.ToShortDateString() method in C# is used to convert the value of the current DateTime object to its equivalent short date string representation.SyntaxFollowing is the syntax −public string ToShortDateString ();ExampleLet us now see an example to implement the DateTime.ToShortDateString() method −using System; public class Demo {    public static void Main() {       DateTime d = new DateTime(2019, 08, 11, 9, 10, 45);       Console.WriteLine("Date = {0}", d);       string str = d.ToShortDateString();       Console.WriteLine("Short date string representation = {0}", str);    } }OutputThis will produce the following output −Date = 8/11/2019 ... Read More

DateTime.ToOADate() Method in C#

AmitDiwan
Updated on 08-Nov-2019 11:07:08

509 Views

The DateTime.ToOADate() method in C# is used to convert the value of this instance to the equivalent OLE Automation date.SyntaxFollowing is the syntax −public double ToOADate ();ExampleLet us now see an example to implement the DateTime.ToOADate() method −using System; public class Demo {    public static void Main() {       DateTime d = new DateTime(2019, 10, 11, 9, 10, 35);       Console.WriteLine("Date = {0}", d);       double res = d.ToOADate();       Console.WriteLine("OLE Automation date = {0}", res);    } }OutputThis will produce the following output −Date = 10/11/2019 9:10:35 AM OLE Automation ... Read More

Char.CompareTo() Method in C#

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

3K+ Views

The Char.CompareTo() method in C# is used to compare this instance to a specified object or value type, and indicates whether this instance precedes, follows, or appears in the same position in the sort order as the specified object or value type.SyntaxFollowing is the syntax −public int CompareTo (char val); public int CompareTo (object val);Above, Val for the 1st syntax is a char object to compare, whereas for the 2nd syntax it is an object to compare this instance to or null.The return value is zero if the current instance has the same position in the sort order as Val. ... Read More

Byte.ToString() Method in C#

AmitDiwan
Updated on 08-Nov-2019 11:03:29

31 Views

The Byte.ToString() method in C# converts the value of the current Byte object to its equivalent string representation.SyntaxFollowing is the syntax −public override string ToString ();ExampleLet us now see an example to implement the Byte.ToString() method −using System; public class Demo {    public static void Main(){       byte val1, val2;       val1 = Byte.MinValue;       val2 = 15;       Console.WriteLine("Value1 (Byte) = "+val1.ToString());       Console.WriteLine("Value2 (Byte) = "+val2.ToString());    } }OutputThis will produce the following output −Value1 (Byte) = 0 Value2 (Byte) = 15

Byte.MinValue Field in C#

AmitDiwan
Updated on 08-Nov-2019 11:02:02

49 Views

The Byte.MinValue field in C# is used to represent the smallest possible value of a Byte.SyntaxFollowing is the syntax −public const byte MinValue = 0;ExampleLet us now see an example to implement the Byte.MinValue method −using System; public class Demo {    public static void Main(){       byte val;       val = Byte.MinValue;       Console.WriteLine("Minimum Value (Byte) = "+val);    } }OutputThis will produce the following output −Minimum Value (Byte) = 0

Byte.MaxValue Field in C#

AmitDiwan
Updated on 08-Nov-2019 11:00:30

175 Views

The Byte.MaxValue field in C# is used to represent the largest possible value of a Byte.SyntaxFollowing is the syntax −public const byte MaxValue = 255;ExampleLet us now see an example to implement the Byte.MaxValue field −using System; public class Demo {    public static void Main(){       byte val;       val = Byte.MaxValue;       Console.WriteLine("Maximum Value (Byte) = "+val);    } }OutputThis will produce the following output −Maximum Value (Byte) = 255

Advertisements