Csharp Articles

Page 104 of 196

Tuple.Create method in C#

George John
George John
Updated on 11-Mar-2026 146 Views

To create a tuple, use the Tuple.Create method.Here we have set a tuple with a string and int −var myTuple = Tuple.Create("marks", 100);The following is an example that creates a tuple using Tuple.Create and displays the elements in a single line in C# −Exampleusing System; class Demo {    static void Main() {       var myTuple = Tuple.Create("marks", 100);       Console.WriteLine(myTuple);    } }Output(marks, 100)

Read More

Set 6-item tuple in C#'

Chandu yadav
Chandu yadav
Updated on 11-Mar-2026 133 Views

With C#, you can easily set a 6-item tuple.The following is a 6-item tuple −var myTuple = new Tuple("electronics", new string[] { "shoes", "clothing#", "accessories" }, 100, 250, 500, 1000);above, we have tuple for string, string array and int as shown below −TupleHere is the complete code −Exampleusing System; class Demo {    static void Main() {       var myTuple = new Tuple("electronics",       new string[] { "shoes", "clothing#", "accessories" },       100,       250,       500,       1000);       // Displaying Item 1       Console.WriteLine(myTuple.Item1);       // Displaying Item 5       Console.WriteLine(myTuple.Item5);       // Displaying Item 6       Console.WriteLine(myTuple.Item6);    } }Outputelectronics 500 1000

Read More

C# Program to check if a character is a whitespace character

Samual Sam
Samual Sam
Updated on 11-Mar-2026 415 Views

Set a character with WhiteSpace −char c = ' ';To check if a character is a whitespace character, use the char.IsWhiteSpace method −if (char.IsWhiteSpace(c)) {}Let us see the complete code −Exampleusing System; class Demo {    static void Main() {       char c = ' ';       if (char.IsWhiteSpace(c)) {          Console.WriteLine("Whitespace character!");       }    } }OutputWhitespace character!

Read More

C# Program to find the largest element from an array

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 3K+ Views

Declare an array −int[] arr = { 20, 50, -35, 25, 60 };Now to get the largest element from an array, use the Max() method −arr.Max());Here is the complete code −Exampleusing System; using System.Linq; class Demo {    static void Main() {       int[] arr = { 20, 50, -35, 25, 60 };       Console.WriteLine(arr.Max());    } }Output60

Read More

C# program to check whether two sequences are the same or not

Samual Sam
Samual Sam
Updated on 11-Mar-2026 220 Views

The SequenceEqual method is used to test collections for equality.Set sequences −string[] arr1 = { "This", "is", "it" }; string[] arr2 = { "My", "work", "report" }; string[] arr3 = { "This", "is", "it" };Now, use the SequenceEquals methods to check whether sequences are same or not −arr1.SequenceEqual(arr2);The following is an example −Exampleusing System; using System.Linq; class Program {    static void Main() {       string[] arr1 = { "This", "is", "it" };       string[] arr2 = { "My", "work", "report" };       string[] arr3 = { "This", "is", "it" };       bool res1 = arr1.SequenceEqual(arr2);       Console.WriteLine(res1);       bool res2 = arr1.SequenceEqual(arr3);       Console.WriteLine(res2);    } }OutputFalse True

Read More

Group by Operator in C#

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 209 Views

Use the group by the operator in C# to separate the results of an expression into parts.Let’s say the following is our array −int[] a = { 5, 10, 15, 20, 25, 30 };Now, using Group by and orderby, we will find the elements greater than 20 −var check = from element in a orderby element group element by chkGreater(element);The following is the complete code −Exampleusing System; using System.Linq; class Demo {    static void Main() {       int[] a = { 5, 10, 15, 20, 25, 30 };       var check = from element in ...

Read More

Round a number to the nearest even number in C#

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 845 Views

The ToEven property is used with the MidpointRounding Enumeration to round a number to the nearest even number.Declare and initialize a decimal number −decimal val = 25.55M;To round a number to the nearest even number −decimal.Round(val, 0, MidpointRounding.ToEven)Here is the complete code −Exampleusing System; using System.Linq; class Demo {    static void Main() {       decimal val = 25.55M;       Console.WriteLine(decimal.Round(val, 0, MidpointRounding.ToEven));    } }Output26

Read More

Decimal constants in C#

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 3K+ Views

Decimal type has constants to get the minimum and maximum values.Set a decimal value −decimal d = 5.8M;To get the minimum and maximum values of the decimal type, use the following properties −decimal.MaxValue decimal.MinValueHere is the complete code −Exampleusing System; using System.Linq; class Demo {    static void Main() {       decimal d = 5.8M;       Console.WriteLine(d);       Console.WriteLine("Maximum Value: "+decimal.MaxValue);       Console.WriteLine("Maximum Value: "+decimal.MinValue);    } }Output5.8 Maximum Value: 79228162514264337593543950335 Maximum Value: -79228162514264337593543950335

Read More

Manipulate decimals with numeric operators in C#

Samual Sam
Samual Sam
Updated on 11-Mar-2026 279 Views

With C#, you can manipulate decimals with operators such as _+, - *, etc.Let us see how to subtract decimal values.Firstly, set two decimal values −decimal d1 = 9.5M; decimal d2 = 4.2M;Now to subtract the two values −d1 = d1 - d2;The following is the code −Exampleusing System; using System.Linq; class Demo {    static void Main() {       decimal d1 = 9.5M;       decimal d2 = 4.2M;       d1 = d1 + d2;       Console.WriteLine("Addition of Decimals: "+d1);       d1 = d1 - d2;       Console.WriteLine("Subtraction of Decimals: "+d1);    } }OutputAddition of Decimals: 13.7 Subtraction of Decimals: 9.5

Read More

C# Program to display temporary file names

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 285 Views

The GetTempPath() method in C# displays temporary file names −Path.GetTempPath();Get the names in a variable and display −string tempFile = Path.GetTempPath();The following is the code −Exampleusing System; using System.IO; class Demo {    static void Main() {       string tempFile = Path.GetTempPath();       Console.WriteLine(tempFile);    } }Output/tmp/

Read More
Showing 1031–1040 of 1,951 articles
« Prev 1 102 103 104 105 106 196 Next »
Advertisements