A read-only property in C# is a property that can only be set during object initialization and cannot be modified afterward. There are several ways to create read-only properties, including using the readonly keyword with fields, properties with only getters, and init-only properties (available in C# 9.0+). Syntax Following is the syntax for a read-only field − readonly dataType fieldName; Following is the syntax for a read-only property with only a getter − public dataType PropertyName { get; } Following is the syntax for an init-only property (C# 9.0+) − ... Read More
In VB.NET, a module is used to store loose code and variables that are accessible from anywhere in the application without needing to instantiate an object. Variables in a module maintain their state throughout the application lifetime. The C# equivalent of a VB.NET module is a static class. Static classes provide the same functionality − global accessibility without instantiation and persistent state through static members. Syntax Following is the syntax for creating a static class in C# − public static class ClassName { public static void MethodName() { ... Read More
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
The Decimal.ToUInt16() method in C# is used to convert the value of the specified Decimal to the equivalent 16-bit unsigned integer (ushort). This method performs a narrowing conversion, truncating any fractional part. Syntax Following is the syntax − public static ushort ToUInt16(decimal val); Parameters val − The decimal number to convert to a 16-bit unsigned integer. Return Value Returns a ushort value that represents the converted decimal. The fractional part is truncated (not rounded). How It Works The method truncates the decimal value to the ... Read More
The Tuple class represents a 7-tuple, also known as a septuple. A tuple is a data structure that contains a fixed number of elements in a specific sequence, allowing you to group related values together. 7-tuples are commonly used for − Easier access to a data set with seven related values. Easier manipulation of a data set. To represent a single set of data with seven components. To return multiple values from a method. To pass multiple values to a method. Syntax Following is the syntax for creating a 7-tuple in C# − ... Read More
Method overloading in C# allows you to define multiple methods with the same name but different parameters. This enables you to create methods that perform similar operations but accept different types or numbers of arguments. Method overloading can be achieved by changing the number of parameters, the data types of parameters, or the order of parameters. The compiler determines which method to call based on the arguments passed at runtime. Syntax Following is the syntax for method overloading − public returnType MethodName(type1 param1) { } public returnType MethodName(type1 param1, type2 param2) { } public returnType ... Read More
Use the AddRange() method to append a second list to an existing list in C#. The AddRange() method adds all elements from one collection to the end of another list, effectively combining two lists into one. Syntax Following is the syntax for using AddRange() method − list1.AddRange(list2); Parameters collection − The collection whose elements should be added to the end of the List. The collection itself cannot be null, but it can contain elements that are null. Using AddRange() Method The AddRange() method modifies the original list by adding ... Read More
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
The DateTime.SpecifyKind() method in C# is used to create a new DateTime object that has the same number of ticks as the specified DateTime but is designated as either local time, Coordinated Universal Time (UTC), or neither, as indicated by the specified DateTimeKind value. This method is particularly useful when you have a DateTime value but need to explicitly specify its time zone context without changing the actual time value. The original DateTime remains unchanged − a new instance is returned with the specified Kind property. Syntax Following is the syntax for the DateTime.SpecifyKind() method − ... Read More
The DateTimeOffset.GetHashCode() method in C# returns a hash code for the current DateTimeOffset object. This method is inherited from the Object class and provides a 32-bit signed integer that represents the unique identifier for the DateTimeOffset instance, which is useful for hash-based collections like Dictionary and HashSet. Syntax Following is the syntax for the GetHashCode() method − public override int GetHashCode(); Return Value This method returns a 32-bit signed integer hash code that represents the current DateTimeOffset object. Two DateTimeOffset objects that are equal will have the same hash code, but objects with ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Economics & Finance