Articles on Trending Technologies

Technical articles with clear explanations and examples

Math.Truncate() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 754 Views

The Math.Truncate() method in C# is used to remove the fractional part of a number and return only the integral part. It works with both decimal and double data types, effectively cutting off all digits after the decimal point without rounding. Syntax The Math.Truncate() method has two overloads − public static decimal Truncate(decimal d) public static double Truncate(double d) Parameters d − A decimal or double number to truncate. Return Value Returns the integral part of the specified number. The return type matches the input parameter type (decimal returns ...

Read More

DateTime.AddMonths() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 5K+ Views

The DateTime.AddMonths() method in C# is used to add the specified number of months to the value of a DateTime instance. This method returns a new DateTime object representing the date after adding the specified months, while the original DateTime remains unchanged. Syntax Following is the syntax for the DateTime.AddMonths() method − public DateTime AddMonths(int months); Parameters months − An integer representing the number of months to add. Use positive values to add months and negative values to subtract months. The value can range from -120, 000 to 120, 000. Return Value ...

Read More

volatile keyword in C#

Samual Sam
Samual Sam
Updated on 17-Mar-2026 842 Views

The volatile keyword in C# is used to indicate that a field might be modified by multiple threads that are executing at the same time. It ensures that the most recent value of a field is present on each read operation, preventing certain compiler optimizations that could lead to unexpected behavior in multithreaded environments. When a field is marked as volatile, the compiler and runtime ensure that reads and writes to that field are not cached or reordered, providing thread-safe access without explicit locking mechanisms. Syntax Following is the syntax for declaring a volatile field − ...

Read More

C# Single() Method

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 2K+ Views

The Single() method in C# returns the only element of a sequence. It throws an exception if the sequence is empty or contains more than one element, making it useful when you expect exactly one element. The Single() method is available in both LINQ to Objects and LINQ to Entities through the System.Linq namespace. Syntax Following is the syntax for the Single() method − public static TSource Single(this IEnumerable source); public static TSource Single(this IEnumerable source, Func predicate); Parameters source − The IEnumerable to return the single element from. predicate − ...

Read More

DateTime.AddSeconds() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 3K+ Views

The DateTime.AddSeconds() method in C# is used to add the specified number of seconds to the value of this instance. This returns a new DateTime object without modifying the original DateTime instance. Syntax Following is the syntax − public DateTime AddSeconds(double sec); Parameters sec − A double value representing the number of seconds to be added. If you want to subtract seconds, then set a negative value. The value can include fractional seconds. Return Value This method returns a new DateTime object that represents the date and time after adding the ...

Read More

C# Multiple Local Variable Declarations

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 866 Views

In C#, you can declare and initialize multiple local variables of the same type in a single statement using the comma operator. This provides a concise way to declare several variables at once, making your code more readable and reducing repetition. Syntax Following is the syntax for declaring multiple local variables of the same type − dataType variable1 = value1, variable2 = value2, variable3 = value3; You can also declare variables without initialization − dataType variable1, variable2, variable3; Basic Multiple Variable Declaration The following example demonstrates declaring four integer ...

Read More

What is the maximum possible value of an integer in C# ?

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 15K+ Views

The maximum possible value of a 32-bit signed integer (int) in C# is 2, 147, 483, 647. This value is also available through the constant int.MaxValue. However, C# provides several integer types with different ranges and maximum values. Integer Types and Their Maximum Values C# offers multiple integer data types, each with different storage sizes and value ranges − Type Size Range Maximum Value sbyte 8-bit signed -128 to 127 127 byte 8-bit unsigned 0 to 255 255 short 16-bit signed -32, 768 to 32, 767 ...

Read More

What is the difference between String and string in C#?

Samual Sam
Samual Sam
Updated on 17-Mar-2026 664 Views

In C#, string and String are functionally identical − string is simply an alias for System.String. Both refer to the same .NET type and can be used interchangeably in your code. Syntax Both declarations are equivalent − string str1 = "Hello World"; String str2 = "Hello World"; Both can use static methods from the String class − string result1 = string.Format("Hello {0}", name); string result2 = String.Format("Hello {0}", name); Key Differences string (lowercase) String (uppercase) C# keyword and alias Actual .NET class ...

Read More

Find a specific element in a C# List

Samual Sam
Samual Sam
Updated on 17-Mar-2026 344 Views

In C#, you can find specific elements in a List using various built-in methods. The most common approach is using the Find() method with a lambda expression to specify search criteria. Syntax Following is the syntax for using the Find() method − T element = list.Find(predicate); Where predicate is a lambda expression that returns true for the element you want to find. Using Find() Method The Find() method returns the first element that matches the specified condition. If no element is found, it returns the default value for the type (0 for ...

Read More

C# Program to return the only element that satisfies a condition

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 394 Views

The Single() method in C# returns the only element from a sequence that satisfies a specified condition. If no element or more than one element satisfies the condition, it throws an InvalidOperationException. This method is part of LINQ and is commonly used when you expect exactly one element to match your criteria. Syntax Following is the syntax for the Single() method − // Without condition - returns the only element public static T Single(this IEnumerable source) // With condition - returns the only element that matches the predicate public static T Single(this IEnumerable source, ...

Read More
Showing 10931–10940 of 61,297 articles
Advertisements