Programming Articles

Page 832 of 2547

How to define multiline String Literal in C#?

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

A multiline string literal in C# allows you to define strings that span multiple lines while preserving the line breaks and formatting. This is achieved using the @ symbol prefix, which creates a verbatim string literal. Syntax Following is the syntax for defining a multiline string literal − string variableName = @"Line 1 Line 2 Line 3"; The @ symbol tells the compiler to treat the string literally, preserving all whitespace, line breaks, and special characters without requiring escape sequences. Using Verbatim String Literals Let's say you want to create a string ...

Read More

What is the difference between a mutable and immutable string in C#?

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

In C#, mutable strings can be modified after creation, while immutable strings cannot be changed once created. The StringBuilder class represents mutable strings, whereas the string class represents immutable strings. When you modify an immutable string, .NET creates a new string object in memory. With mutable strings using StringBuilder, modifications are made to the existing object without creating new memory allocations. Immutable String A string in C# is immutable, meaning once created, it cannot be modified. Any operation that appears to modify a string actually creates a new string object in memory. Syntax string ...

Read More

C# Program to get information about a file

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

To get information about a file means to retrieve the attributes and properties associated with that particular file. File attributes indicate characteristics such as whether a file is normal, hidden, archived, read-only, or a system file. In C#, the FileInfo class provides comprehensive information about files, including attributes, size, creation time, and modification time. Syntax Following is the syntax for creating a FileInfo object and getting file attributes − FileInfo info = new FileInfo("filename.txt"); FileAttributes attr = info.Attributes; Using FileInfo to Get File Attributes The FileAttributes enumeration represents various file attributes that ...

Read More

C# Program to find the sum of a sequence

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

A sequence in C# is a collection of elements that can be processed using LINQ methods. To find the sum of a sequence, you can use several approaches including the Sum() method from LINQ, which provides a simple and efficient way to calculate the total. The most common approach is using the LINQ Sum() method, which can be applied to any IEnumerable collection. Syntax Following is the syntax for using the Sum() method − // For numeric collections collection.Sum(); // With selector function collection.Sum(x => x.Property); Using LINQ Sum() Method The ...

Read More

CharEnumerator.ToString() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 97 Views

The CharEnumerator.ToString() method in C# returns a string representation of the current CharEnumerator object. This method is inherited from the Object class and provides basic type information about the enumerator instance. Syntax Following is the syntax − public override string ToString(); Return Value The method returns a string that represents the current object. For CharEnumerator, this typically returns the fully qualified type name "System.CharEnumerator". Using CharEnumerator.ToString() Method Example Let us see an example to implement the CharEnumerator.ToString() method − using System; public class Demo { ...

Read More

DateTimeOffset.AddDays() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 554 Views

The DateTimeOffset.AddDays() method in C# returns a new DateTimeOffset object that adds a specified number of whole and fractional days to the value of the current instance. This method allows you to add or subtract days while preserving the original timezone offset information. Syntax Following is the syntax − public DateTimeOffset AddDays(double days); Parameters days − A number of whole and fractional days. The value parameter can be negative or positive. Return Value Returns a new DateTimeOffset object whose value is the sum of the date and time represented ...

Read More

Thread Pools in C#

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

A thread pool in C# is a collection of pre-created threads that can be reused to execute multiple tasks efficiently. Instead of creating new threads for each task, the thread pool manages a pool of worker threads, reducing the overhead of thread creation and destruction. The ThreadPool class in the System.Threading namespace provides methods to queue work items for execution by background threads. When a thread completes its task, it returns to the pool and waits for the next available work item. Syntax Following is the syntax for queuing work items to the thread pool − ...

Read More

C# Program to get the last write time of a file

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

To get the last write time of a file in C#, you can use the LastWriteTime property of the FileInfo class. This property returns a DateTime object representing when the file was last modified. You can also use the static File.GetLastWriteTime() method as an alternative approach for retrieving the last write time without creating a FileInfo instance. Syntax Using FileInfo class − FileInfo fileInfo = new FileInfo("filename.txt"); DateTime lastWrite = fileInfo.LastWriteTime; Using File.GetLastWriteTime() method − DateTime lastWrite = File.GetLastWriteTime("filename.txt"); Using FileInfo Class The FileInfo class provides comprehensive file ...

Read More

C# Queryable Take() Method

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

The Take() method in C# is a LINQ extension method that returns a specified number of contiguous elements from the start of a sequence. It's commonly used with IQueryable collections to limit the number of results returned from a query. Syntax Following is the syntax for the Take() method − public static IQueryable Take( this IQueryable source, int count ) Parameters source − The IQueryable to return elements from. count − The number of elements to return. Return Value ...

Read More

How do you use a 'for loop' for accessing array elements in C#?

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

The for loop in C# executes a sequence of statements multiple times and is commonly used to iterate through arrays. It provides a clean way to access and manipulate array elements using an index variable that increments automatically. Syntax Following is the syntax for a for loop used with arrays − for (int i = 0; i < arrayName.Length; i++) { // Access array element using arrayName[i] } The for loop has three parts − Initialization: int i = 0 sets the starting index Condition: i < arrayName.Length continues ...

Read More
Showing 8311–8320 of 25,466 articles
« Prev 1 830 831 832 833 834 2547 Next »
Advertisements