Found 2587 Articles for Csharp

Implicit conversion from Byte to Decimal in C#

Ankith Reddy
Updated on 23-Jun-2020 08:44:39

421 Views

Byte represents an 8-bit unsigned integer.Implicit conversion of an 8-bit unsigned integer (Byte) to a Decimal is possible. Let us see how.Here’s our Byte value.byte val = 16;To implicitly convert, just assign the value as shown below −decimal dec; dec = val;Let us see the complete example.Example Live Demousing System; public class Demo {    public static void Main() {       byte val = 16;       decimal dec;       // implicit       dec = val;       Console.WriteLine("Decimal ="+dec);    } }OutputDecimal =16

C# Program to convert a Double to an Integer Value

Samual Sam
Updated on 23-Jun-2020 08:45:01

17K+ Views

To convert a Double value to an integer value, use the Convert.ToInt32() method.Int32 represents a 32-bit signed integer.Let’s say the following is our double value.double val = 21.34;Now to convert it to Int32.int res = Convert.ToInt32(val);Let us see the complete example.Example Live Demousing System; public class Demo {    public static void Main() {       double val = 21.34;       int res = Convert.ToInt32(val);       Console.WriteLine("Converted double {0} to integer {1} ", val, res);    } }OutputConverted double 21.34 to integer 21

C# Any Method

Arjun Thakur
Updated on 23-Jun-2020 08:46:29

9K+ Views

The Any method checks whether any of the element in a sequence satisfy a specific condition or not.If any element satisfy the condition, true is returned.Let us see an example.int[] arr = {5, 7, 10, 12, 15, 18, 20};Now, using Any() method, we will check whether any of the element in the above array is greater than 10 or not.arr.AsQueryable().All(val => val > 5);If any of the element satisfies the condition, then True is returned.Let us see the complete example.Example Live Demousing System; using System.Linq; class Demo {    static void Main() {       int[] arr = {5, 7, ... Read More

C# Program to convert a Double value to an Int64 value

karthikeya Boyini
Updated on 23-Jun-2020 08:47:13

2K+ Views

To convert a Double value to an Int64 value, use the Convert.ToInt64() method.Int64 represents a 64-bit signed integer.Let’s say the following is our double value.double val = 23.951213e12;Now to convert it to Int64.long longVal = Convert.ToInt64(val);Let us see the complete example.Example Live Demousing System; public class Demo {    public static void Main() {       double val = 23.951213e12;       long longVal = Convert.ToInt64(val);       Console.WriteLine("Converted double {0:E} to Int64 {1:N0} value ", val, longVal);    } }OutputConverted double 2.395121E+013 to Int64 23,951,213,000,000 value

C# Program to convert a Byte value to an Int32 value

Chandu yadav
Updated on 23-Jun-2020 08:47:57

8K+ Views

To convert a Byte value to an Int32 value, use the Convert.ToInt32() method.Int32 represents a 32-bit signed integer.Let’s say the following is our Byte value.byte val = Byte.MaxValue;;Now to convert it to Int32.int intVal = Convert.ToInt32(val);Let us see the complete example.Example Live Demousing System; public class Demo {    public static void Main() {       byte val = Byte.MaxValue;;       int intVal = Convert.ToInt32(val);       Console.WriteLine("Converted byte {0} to Int32 {1} value ", val, intVal);    } }OutputConverted byte 255 to Int32 255 value

C# Program to convert an Int32 value to a decimal

Samual Sam
Updated on 23-Jun-2020 08:48:26

3K+ Views

To convert an Int32 value to a decimal, use the Convert.ToDecimal() method.Int32 represents a 32-bit signed integer.Let’s say the following is our Int32 value.int val = 2923;Now to convert it to decimal.decimal decVal = Convert.ToDecimal(val);Let us see the complete example.Example Live Demousing System; public class Demo {    public static void Main() {       int val = 2923;       decimal decVal = Convert.ToDecimal(val);       Console.WriteLine("Converted Int32 {0} to decimal {1:N2} value ", val, decVal);    } }OutputConverted Int32 2923 to decimal 2,923.00 value

ArgumentNullException in C#

George John
Updated on 23-Jun-2020 08:49:16

796 Views

The exception thrown when a null reference is passed to a method that does not accept it as a valid argument.Let us see an example.When we set a null parameter to int.Parse() method, then ArgumentNullException is thrown as shown below −Exampleusing System; class Demo {    static void Main() {       string val = null;       int res = int.Parse(val); // error is thrown    } }OutputThe following error is thrown when the above program is compiled since we have passed a null value.Unhandled Exception: System.ArgumentNullException: Value cannot be null.

Get bounds of a C# three-dimensional array

Ankith Reddy
Updated on 23-Jun-2020 08:37:49

502 Views

To get the bounds of a three-dimensional array, use the GetUpperBound() GetLowerBound() methods in C#.The parameter to be set under these methods is the dimensions i.e.Let’s say our array is −int[, , ] arr = new int[3, 4, 5];For a three-dimensional arrays, dimension 0.arr.GetUpperBound(0) arr.GetLowerBound(0)For a three-dimensional arrays, dimension 1.arr.GetUpperBound(1) arr.GetLowerBound(1)For a three-dimensional arrays, dimension 2.arr.GetUpperBound(2) arr.GetLowerBound(2)Let us see the entire example.Example Live Demousing System; class Program {    static void Main() {       int[, , ] arr = new int[3, 4, 5];       Console.WriteLine("Dimension 0 Upper Bound: {0}", arr.GetUpperBound(0).ToString());       Console.WriteLine("Dimension 0 Lower Bound: ... Read More

Get the width and height of a three-dimensional array

karthikeya Boyini
Updated on 23-Jun-2020 08:37:18

311 Views

Let’s say our three-dimensional array is −int[,,] arr = new int[3,4,5];To get the height and width i.e. the rows and columns.Array.GetLength(0) – for rows Array.GetLength(1) – for columnsExample Live Demousing System; class Program {    static void Main() {       int[,,] arr = new int[3,4,5];       Console.WriteLine(arr.GetLength(0));       Console.WriteLine(arr.GetLength(1));       Console.WriteLine(arr.GetLength(2));    } }Output3 4 5

Get rank of a three-dimensional array in C#

Arjun Thakur
Updated on 23-Jun-2020 08:39:23

166 Views

To get the rank of a three-dimensional array, use the Rank property.Set a three-dimensional array.int[,,] arr = new int[3,4,5]Now get the rank.arr.RankLet us see the complete code.Exampleusing System; class Program {    static void Main() {       int[,,] arr = new int[3,4,5]       Console.WriteLine("Dimensions of Array : " + arr.Rank);    } }

Advertisements