Server Side Programming Articles

Page 842 of 2109

Character constants vs String literals in C#

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

In C#, both character constants and string literals are used to represent text data, but they serve different purposes and have distinct syntax rules. Character constants represent single characters, while string literals represent sequences of characters (text). Character Constants Character constants are enclosed in single quotes and represent a single character. They are stored in variables of type char. Syntax char variableName = 'character'; Character constants can be − Plain characters − 'x', 'A', '5' Escape sequences − '', '\t', '' Unicode characters − '\u0041' (represents 'A') Example ...

Read More

What is the IsReadOnly property of SortedList class in C#?

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

The IsReadOnly property of the SortedList class in C# returns a boolean value indicating whether the collection is read-only. A read-only collection cannot be modified after creation − you cannot add, remove, or update elements. For standard SortedList instances created using the default constructor, this property always returns false, meaning the collection is modifiable. Syntax Following is the syntax for using the IsReadOnly property − bool isReadOnly = sortedList.IsReadOnly; Return Value The IsReadOnly property returns − true − if the SortedList is read-only false − if the SortedList can be ...

Read More

Check if a File is hidden in C#

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

To check if a file is hidden in C#, use the FileAttributes enumeration which contains various file attribute members like Compressed, Directory, Hidden, and others. The FileAttributes.Hidden flag indicates whether a file has the hidden attribute set. You can retrieve file attributes using File.GetAttributes() and then check for the Hidden flag using bitwise operations. Syntax Following is the syntax for getting file attributes − FileAttributes attributes = File.GetAttributes(filePath); Following is the syntax for checking if a file is hidden − bool isHidden = (attributes & FileAttributes.Hidden) == FileAttributes.Hidden; Using ...

Read More

Check if a File exists in C#

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

The File.Exists() method in C# is used to check whether a file exists at a specified path. This method returns true if the file exists, and false if it does not. It is part of the System.IO namespace and provides a simple way to verify file existence before performing file operations. Syntax Following is the syntax for the File.Exists() method − public static bool Exists(string path) Parameters path − The file path to check. Can be a relative path (current directory) or absolute path (full path including drive). Return Value ...

Read More

What is the IsFixedSize property of Hashtable class in C#?

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

The IsFixedSize property of the Hashtable class in C# returns a bool value indicating whether the Hashtable has a fixed size. When this property returns false, you can add or remove elements. When it returns true, the size is fixed and you cannot add or remove elements. For a regular Hashtable created using the default constructor, IsFixedSize always returns false, meaning it can grow dynamically as you add elements. Syntax Following is the syntax to check if a Hashtable has a fixed size − bool isFixed = hashtable.IsFixedSize; Return Value The IsFixedSize ...

Read More

Check if both halves of the string have same set of characters in C#

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

To check if both halves of a string have the same set of characters in C#, we need to split the string into two equal halves and compare the character frequencies in each half. This problem is useful for validating palindromic properties and string pattern matching. Algorithm The approach uses character frequency counting − Create two frequency arrays to count characters in each half Iterate from both ends of the string toward the center Count character occurrences in the left half and right half Compare the frequency arrays to determine if both halves contain the same ...

Read More

char vs string keywords in C#

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

The char and string keywords in C# are used to work with textual data, but they serve different purposes. The char keyword represents a single character, while string represents a sequence of characters. Understanding the difference between these two data types is essential for effective text manipulation in C#. Syntax Following is the syntax for declaring a char variable − char variableName = 'A'; // Single quotes for character Following is the syntax for declaring a string variable − string variableName = "Hello"; // Double quotes for string ...

Read More

Comparing enum members in C#

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

To compare enum members in C#, you can use the Enum.CompareTo() method or standard comparison operators. Enum comparison is based on the underlying numeric values assigned to each enum member. Syntax Following is the syntax for using CompareTo() method − enumValue1.CompareTo(enumValue2) Following is the syntax for using comparison operators − enumValue1 == enumValue2 // equality enumValue1 > enumValue2 // greater than enumValue1 < enumValue2 // less than Return Value The CompareTo() method returns − Negative value if the first enum is ...

Read More

Compute modulus division by a power-of-2-number in C#

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

Computing modulus division by a power-of-2 number in C# can be optimized using bitwise operations. When the divisor is a power of 2 (like 2, 4, 8, 16, etc.), we can use the bitwise AND operation with (divisor - 1) instead of the traditional modulus operator for better performance. This optimization works because powers of 2 in binary have only one bit set, and subtracting 1 creates a mask that isolates the relevant lower bits. Syntax Following is the syntax for computing modulus with a power-of-2 divisor − result = dividend & (divisor - 1); ...

Read More

Compressing and Decompressing files in C#

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

File compression and decompression in C# is accomplished using the System.IO.Compression namespace. This namespace provides classes like GZipStream and ZipArchive for handling compressed files efficiently. Syntax Following is the syntax for compressing files using GZipStream − using (var compressStream = new GZipStream(outputStream, CompressionMode.Compress)) { // write data to compress } Following is the syntax for decompressing files using GZipStream − using (var decompressStream = new GZipStream(inputStream, CompressionMode.Decompress)) { // read decompressed data } Using GZipStream for File Compression To compress a ...

Read More
Showing 8411–8420 of 21,090 articles
« Prev 1 840 841 842 843 844 2109 Next »
Advertisements