Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Csharp Articles
Page 141 of 196
Tuple.Create method in C#
The Tuple.Create method in C# is a convenient way to create tuple objects without explicitly specifying their types. The method automatically infers the types from the provided arguments, making tuple creation more concise and readable. Syntax Following is the syntax for using Tuple.Create method − var tupleName = Tuple.Create(item1, item2, ...); The method can accept up to 8 parameters of different types − Tuple.Create(T1 item1); Tuple.Create(T1 item1, T2 item2); // ... up to 8 items Creating Basic Tuples Example Here we create a tuple with a string and ...
Read MoreSet 6-item tuple in C#'
A 6-item tuple in C# is a data structure that can hold six values of different or same data types. Tuples are useful when you need to return multiple values from a method or group related data together without creating a separate class. Syntax Following is the syntax for creating a 6-item tuple using the Tuple class − var tuple = new Tuple(item1, item2, item3, item4, item5, item6); Alternatively, you can use the modern tuple syntax with parentheses − var tuple = (item1, item2, item3, item4, item5, item6); Using Traditional ...
Read MoreC# Program to check if a character is a whitespace character
In C#, a whitespace character includes spaces, tabs, newlines, and other invisible characters used for formatting text. The char.IsWhiteSpace() method provides an easy way to identify these characters programmatically. Syntax Following is the syntax for using char.IsWhiteSpace() method − bool result = char.IsWhiteSpace(character); Parameters The method takes a single parameter − character − The character to be tested for whitespace. Return Value Returns true if the character is a whitespace character; otherwise, returns false. Using char.IsWhiteSpace() with Different Whitespace Characters The method recognizes various types of ...
Read MoreC# program to check whether two sequences are the same or not
The SequenceEqual method in C# is a LINQ extension method that determines whether two sequences are equal by comparing their elements using the default equality comparer. It returns true if the sequences have the same length and corresponding elements are equal, otherwise it returns false. Syntax Following is the syntax for using SequenceEqual method − bool result = sequence1.SequenceEqual(sequence2); You can also use a custom equality comparer − bool result = sequence1.SequenceEqual(sequence2, comparer); Parameters sequence2 − The sequence to compare with the current sequence. comparer ...
Read MoreGroup by Operator in C#
The Group By operator in C# is used to group elements in a collection based on a specified key. It separates the results into groups where each group contains elements that share the same key value. Syntax Following is the syntax for using Group By with LINQ query syntax − var result = from element in collection group element by keySelector; Following is the syntax for using Group By with method syntax − var result = collection.GroupBy(keySelector); ...
Read MoreRound a number to the nearest even number in C#
The MidpointRounding.ToEven option is used with rounding methods in C# to round a number to the nearest even number when the fractional part is exactly 0.5. This is also known as banker's rounding or round half to even. Syntax Following is the syntax for rounding to the nearest even number − decimal.Round(value, digits, MidpointRounding.ToEven) Math.Round(value, digits, MidpointRounding.ToEven) Parameters value − The decimal or double number to be rounded digits − The number of decimal places in the return value MidpointRounding.ToEven − Rounds to the nearest even number ...
Read MoreDecimal type in C#
The decimal type in C# is a 128-bit data type designed for financial and monetary calculations that require high precision. Unlike float and double, the decimal type provides exact decimal representation without rounding errors, making it ideal for applications involving currency and precise arithmetic operations. Syntax Following is the syntax for declaring decimal variables − decimal variableName = value; decimal variableName = valueM; // M or m suffix required for literals The M or m suffix is required when assigning decimal literals to distinguish them from double values − decimal price = ...
Read MoreDecimal constants in C#
The decimal type in C# provides built-in constants to retrieve the minimum and maximum possible values for decimal numbers. These constants are useful for validation, range checking, and initialization purposes. Syntax Following is the syntax for declaring a decimal constant − decimal variableName = value M; Following is the syntax for accessing decimal constants − decimal.MaxValue // Maximum possible decimal value decimal.MinValue // Minimum possible decimal value Decimal Constants The decimal type provides two important constants − decimal.MaxValue − Returns the largest possible decimal ...
Read MoreManipulate decimals with numeric operators in C#
The decimal data type in C# provides precise arithmetic operations for financial and monetary calculations. You can manipulate decimals using standard numeric operators such as +, -, *, /, and %. Decimal literals in C# must be suffixed with M or m to distinguish them from double values. This ensures precision is maintained during calculations. Syntax Following is the syntax for declaring decimal variables − decimal variableName = value M; Following is the syntax for basic arithmetic operations with decimals − decimal result = decimal1 + decimal2; // Addition decimal ...
Read MoreC# Program to display temporary file names
The Path.GetTempPath() method in C# retrieves the path of the system's temporary folder where temporary files are stored. This method is useful when your application needs to create temporary files or work with the system's designated temporary directory. Syntax Following is the syntax for using Path.GetTempPath() method − string tempPath = Path.GetTempPath(); Return Value The method returns a string representing the path to the system's temporary directory. On Windows, this is typically the path specified by the TEMP or TMP environment variables. On Unix-like systems, it's usually /tmp/. Using GetTempPath() to Display ...
Read More