Server Side Programming Articles

Page 826 of 2109

Display the default if element is not found in a C# List

George John
George John
Updated on 17-Mar-2026 179 Views

When working with C# Lists, attempting to access an element that doesn't exist can throw exceptions. To safely handle empty lists or missing elements, you can use methods like FirstOrDefault() which return the default value for the type instead of throwing an exception. For reference types like strings, the default value is null. For value types like int, float, or double, the default value is 0. For bool, it's false. Syntax Following is the syntax for using FirstOrDefault() on a List − list.FirstOrDefault(); list.FirstOrDefault(condition); You can also specify a custom default value using ...

Read More

Difference between TimeSpan Seconds() and TotalSeconds()

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

The TimeSpan.Seconds property returns only the seconds component of a time span, whereas TimeSpan.TotalSeconds property converts the entire time duration into seconds. Understanding this difference is crucial when working with time calculations in C#. Syntax Following is the syntax for accessing the seconds component − TimeSpan ts = new TimeSpan(days, hours, minutes, seconds, milliseconds); int seconds = ts.Seconds; Following is the syntax for getting total seconds − TimeSpan ts = new TimeSpan(days, hours, minutes, seconds, milliseconds); double totalSeconds = ts.TotalSeconds; How It Works TimeSpan: 1 ...

Read More

Convert.ToChar Method in C#

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 1K+ Views

The Convert.ToChar() method in C# converts a specified value to its equivalent Unicode character representation. This method accepts various data types including integers, bytes, strings, and other numeric types, and returns a char value. Syntax Following are the common overloads of the Convert.ToChar() method − public static char ToChar(byte value) public static char ToChar(int value) public static char ToChar(string value) public static char ToChar(object value) Parameters value − The value to be converted to a Unicode character. This can be a numeric type, string, or object. Return Value ...

Read More

Convert.ToDateTime Method in C#

Samual Sam
Samual Sam
Updated on 17-Mar-2026 1K+ Views

The Convert.ToDateTime method in C# converts a string representation of a date and time to a DateTime object. This method is commonly used when you need to parse date strings from user input, files, or external data sources into a usable DateTime format. The method supports various date formats and provides automatic parsing based on the current culture settings of your system. Syntax Following are the most commonly used overloads of Convert.ToDateTime − public static DateTime ToDateTime(string value) public static DateTime ToDateTime(string value, IFormatProvider provider) public static DateTime ToDateTime(object value) Parameters ...

Read More

Different Star Pattern Programs in C#

George John
George John
Updated on 17-Mar-2026 27K+ Views

Star pattern programs are common programming exercises that help developers practice loops and understand nested iteration logic. C# provides simple syntax to create various star patterns using for loops and Console.Write() methods. Common Star Pattern Types Right Triangle * ** Pyramid * *** Inverted *** ** Diamond * *** Right Triangle Pattern This pattern creates a right-angled triangle where each row contains one more star than the previous row − using System; class Program { static void Main() { for (int i = 1; i

Read More

C# Program to merge sequences

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

In C#, you can merge sequences using the Zip method from LINQ. The Zip method combines elements from two sequences by pairing them together using a specified function. Syntax The Zip method syntax is − sequence1.Zip(sequence2, (first, second) => result) Parameters sequence1 − The first sequence to merge sequence2 − The second sequence to merge resultSelector − A function that defines how to combine elements from both sequences How It Works The Zip method pairs elements from two sequences by their index position. If sequences have different lengths, the ...

Read More

C# Program to create a LinkedList

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 352 Views

A LinkedList in C# is a generic collection that stores elements in nodes, where each node contains the data and references to the next and previous nodes. Unlike arrays, LinkedList elements are not stored in contiguous memory locations and allow efficient insertion and removal operations. Syntax Following is the syntax for creating a LinkedList − LinkedList listName = new LinkedList(); You can also create a LinkedList from an existing collection − LinkedList listName = new LinkedList(collection); Creating LinkedList from Array You can create a LinkedList by passing an array ...

Read More

C# Program to invert the order of elements in a sequence

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

In C#, you can invert the order of elements in a sequence using several built-in methods. The most common approaches include using Queryable.Reverse() with LINQ, Array.Reverse(), and Enumerable.Reverse(). Each method has its specific use cases and performance characteristics. Syntax Following is the syntax for using Queryable.Reverse() method − IQueryable result = sequence.AsQueryable().Reverse(); Following is the syntax for using Array.Reverse() method − Array.Reverse(array); Following is the syntax for using Enumerable.Reverse() method − IEnumerable result = sequence.Reverse(); Using Queryable.Reverse() Method The Queryable.Reverse() method returns an IQueryable that ...

Read More

C# Program to return a collection with repeated elements

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 396 Views

To return a collection with repeated elements in C#, use the Enumerable.Repeat method from the System.Linq namespace. This method creates a sequence that contains one repeated value a specified number of times. Syntax Following is the syntax for Enumerable.Repeat method − public static IEnumerable Repeat(TResult element, int count) Parameters element − The value to be repeated in the result sequence. count − The number of times to repeat the value in the generated sequence. Return Value Returns an IEnumerable that contains a repeated value. ...

Read More

Convert.ToInt32 Method in C#

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

The Convert.ToInt32() method in C# converts a specified value to a 32-bit signed integer. This method provides type conversion from various data types including string, double, float, decimal, and bool to int. The method uses rounding to nearest even (banker's rounding) when converting floating-point numbers, and throws exceptions for invalid conversions like null strings or out-of-range values. Syntax Following are the common overloads of Convert.ToInt32() method − Convert.ToInt32(object value) Convert.ToInt32(string value) Convert.ToInt32(double value) Convert.ToInt32(bool value) Parameters value − The value to convert to a 32-bit signed integer. Return Value ...

Read More
Showing 8251–8260 of 21,090 articles
« Prev 1 824 825 826 827 828 2109 Next »
Advertisements