Server Side Programming Articles

Page 811 of 2109

Get the range of elements in a C# list

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

The GetRange() method in C# is used to extract a subset of elements from a List. This method returns a new list containing the specified range of elements from the original list, without modifying the original list. Syntax Following is the syntax for the GetRange() method − public List GetRange(int index, int count) Parameters index − The zero-based starting index of the range to extract. count − The number of elements to extract from the starting index. Return Value Returns a new List containing the specified range of elements. ...

Read More

Remove duplicates from a List in C#

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

Removing duplicates from a List in C# is a common task when working with collections. There are several approaches to accomplish this, with Distinct() being the most straightforward method. The Distinct() method uses LINQ to filter out duplicate elements based on their default equality comparison. Syntax Following is the syntax for using Distinct() to remove duplicates − List uniqueList = originalList.Distinct().ToList(); For custom equality comparison − List uniqueList = originalList.Distinct(comparer).ToList(); Using Distinct() Method The Distinct() method from LINQ is the simplest way to remove duplicates from a list. It ...

Read More

Null List in C#

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

A null list in C# refers to a List reference that points to nothing instead of an actual List object. This is different from an empty list, which is an initialized List with zero elements. Understanding null lists is crucial for avoiding NullReferenceException errors in your applications. Syntax To declare a null list − List listName = null; To check if a list is null − if (listName == null) { // handle null case } Creating and Checking Null Lists When you declare a List ...

Read More

C# Program to Subtract Two TimeSpan

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

In C#, the TimeSpan structure represents a time interval and provides methods to perform arithmetic operations. To subtract one TimeSpan from another, you can use the Subtract() method or the subtraction operator (-). Syntax Following is the syntax for subtracting TimeSpan objects using the Subtract() method − TimeSpan result = timeSpan1.Subtract(timeSpan2); Following is the syntax using the subtraction operator − TimeSpan result = timeSpan1 - timeSpan2; Using Subtract() Method The Subtract() method returns a new TimeSpan that represents the difference between two TimeSpan values − using System; ...

Read More

C# program to Loop over a two dimensional array

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

A two-dimensional array in C# stores elements in a grid format with rows and columns. To loop through all elements, you need to iterate through both dimensions using nested loops. Syntax Following is the syntax for declaring a two-dimensional array − dataType[,] arrayName = new dataType[rows, columns]; Following is the syntax for looping through a two-dimensional array using nested for loops − for (int i = 0; i

Read More

C# program to display the next day

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 3K+ Views

To display the next day in C#, use the AddDays() method with a value of 1. The AddDays() method adds or subtracts days from a DateTime object and returns a new DateTime representing the modified date. Syntax Following is the syntax for using AddDays() method − DateTime.AddDays(double value) Parameters value − A number of whole and fractional days. Use positive values for future dates and negative values for past dates. Return Value The method returns a new DateTime object that represents the date and time with the ...

Read More

C# Program to display the number of days in a month

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

The DateTime.DaysInMonth() method in C# is used to display the number of days in a specific month and year. This static method is particularly useful when working with calendar calculations or when you need to validate dates. Syntax Following is the syntax for using DateTime.DaysInMonth() − int days = DateTime.DaysInMonth(year, month); Parameters year: An integer representing the year (1 to 9999). month: An integer representing the month (1 to 12). Return Value Returns an integer representing the number of days in the specified month and ...

Read More

TimeSpan.From methods in C# ()

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

The TimeSpan.From methods in C# provide a convenient way to create TimeSpan objects from specific time units. These static methods include FromDays, FromHours, FromMinutes, FromSeconds, FromMilliseconds, and FromTicks. Each method takes a numeric value and returns a TimeSpan representing that duration in the specified unit. This approach is more readable than manually calculating ticks or using TimeSpan constructors. Syntax Following are the syntax formats for the most commonly used TimeSpan.From methods − TimeSpan.FromDays(double value) TimeSpan.FromHours(double value) TimeSpan.FromMinutes(double value) TimeSpan.FromSeconds(double value) TimeSpan.FromMilliseconds(double value) TimeSpan.FromTicks(long value) Parameters All TimeSpan.From methods (except FromTicks) accept a ...

Read More

C# Program to Add Two TimeSpan

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

The TimeSpan structure in C# represents a time interval and provides methods to perform arithmetic operations. You can add two TimeSpan objects using the Add() method or the + operator to get the combined duration. Syntax Following is the syntax for adding two TimeSpan objects using the Add() method − TimeSpan result = timespan1.Add(timespan2); You can also use the + operator for addition − TimeSpan result = timespan1 + timespan2; Using the Add() Method The Add() method returns a new TimeSpan that represents the sum of two time intervals ...

Read More

C# TicksPer constants

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

The TicksPer constants in C# are predefined values in the TimeSpan class that represent the number of ticks for different time units. A tick is the smallest unit of time measurement in .NET, where one tick equals 100 nanoseconds. These constants help convert between ticks and common time measurements. Available TicksPer Constants The TimeSpan class provides the following TicksPer constants − TicksPerDay − Number of ticks in one day TicksPerHour − Number of ticks in one hour TicksPerMinute − Number of ticks in one minute TicksPerSecond − Number of ticks in one second TicksPerMillisecond − Number ...

Read More
Showing 8101–8110 of 21,090 articles
« Prev 1 809 810 811 812 813 2109 Next »
Advertisements