Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Programming Articles
Page 59 of 2547
Thread.CurrentThread Property in C#
The Thread.CurrentThread property in C# is used to get a reference to the currently executing thread. This static property returns the Thread object representing the thread that is currently running, allowing you to access information about the current thread's state, name, ID, and other properties. Syntax The syntax for accessing the current thread is as follows − public static System.Threading.Thread CurrentThread { get; } Return Value This property returns a Thread object that represents the currently executing thread. Through this object, you can access various thread properties and methods. Using Thread.CurrentThread for ...
Read MoreConvert Decimal to equivalent 8-bit unsigned integer in C#
To convert a Decimal value to an equivalent 8-bit unsigned integer (byte), C# provides the Decimal.ToByte() method. This method truncates the decimal portion and converts the integer part to a byte value, which ranges from 0 to 255. The conversion follows banker's rounding rules for values exactly between two integers, and throws an OverflowException if the decimal value is outside the valid byte range. Syntax Following is the syntax for converting decimal to byte − byte result = Decimal.ToByte(decimalValue); Parameters decimalValue − The decimal number to convert to a byte. Must ...
Read MoreHow to write retry logic in C#?
Retry logic is implemented to handle transient failures that may resolve themselves after a brief delay. This pattern is essential when working with network operations, database connections, or external APIs that may temporarily fail due to network issues, service overload, or temporary unavailability. It's important to log all connectivity failures that cause a retry so that underlying problems with the application, services, or resources can be identified. Implement retry logic only where you have the full context of a failing operation and when the operation is idempotent (safe to repeat). Syntax Following is the basic syntax for ...
Read MoreStringBuilder.Chars[] Property in C#
The StringBuilder.Chars[] property in C# provides indexed access to individual characters within a StringBuilder instance. This property allows you to both get and set characters at specific positions, making it useful for character-level manipulations without converting the entire StringBuilder to a string. Syntax Following is the syntax for the StringBuilder.Chars[] property − public char this[int index] { get; set; } Parameters index − The zero-based position of the character to get or set. Must be within the bounds of the StringBuilder (0 to Length-1). Return Value Returns ...
Read MoreCheck whether the Unicode character is a separator character in C#
The Char.IsSeparator() method in C# determines whether a Unicode character belongs to the separator category. Unicode separator characters are used to separate words, lines, or paragraphs in text, such as spaces, line separators, and paragraph separators. Syntax Following is the syntax for the Char.IsSeparator() method − public static bool IsSeparator(char c) public static bool IsSeparator(string s, int index) Parameters c − The Unicode character to evaluate. s − A string containing the character to evaluate. index − The position of the character to evaluate in the string. Return Value ...
Read MoreWhat is the difference between IEnumerable and IQueryable in C#?
The IEnumerable and IQueryable interfaces are both used for querying collections in C#, but they differ significantly in how they execute queries and handle data. Understanding these differences is crucial for writing efficient database queries and managing memory usage. Key Differences Feature IEnumerable IQueryable Namespace System.Collections System.Linq Query Execution In-memory (client-side) Server-side (database) Lazy Loading Not supported Supported Extension Methods Use functional objects Use expression trees Best For In-memory collections Database queries Syntax Following is the syntax for ...
Read MoreHow to implement interface in anonymous class in C#?
No, anonymous types cannot implement an interface. We need to create your own type. Anonymous types provide a convenient way to encapsulate a set of read-only properties into a single object without having to explicitly define a type first. The type name is generated by the compiler and is not available at the source code level. The type of each property is inferred by the compiler. Syntax Following is the syntax for creating anonymous types − var anonymousObject = new { Property1 = value1, Property2 = value2 }; Why Anonymous Types Cannot Implement ...
Read MoreCapacity of a SortedList in C#
The Capacity property of a SortedList in C# represents the maximum number of key-value pairs that the SortedList can hold without needing to resize its internal storage. This is different from the Count property, which shows the actual number of elements currently stored. When elements are added to a SortedList, the capacity automatically grows to accommodate new items. The capacity typically doubles when the current capacity is exceeded, following a geometric growth pattern to optimize performance. Syntax Following is the syntax to get the capacity of a SortedList − int capacity = sortedList.Capacity; ...
Read MoreWhat is bin and obj folder in C#?
Whenever we write a C# code and build or run the solution, it generates 2 folders − bin folder obj folder These folders contain compiled code at different stages of the compilation process. Understanding the difference between them is crucial for C# developers working with build systems and deployment. Why Two Folders? The compilation process in C# goes through multiple stages, which is why we have separate folders for different outputs − Compiling − Individual source files are compiled into intermediate objects Linking − All compiled objects are linked together into the ...
Read MoreWhat is difference between using if/else and switch-case in C#?
The switch statement and if-else statements are both selection statements in C# used for decision-making, but they serve different purposes and have distinct performance characteristics. The switch statement chooses a single section to execute from a list of candidates based on pattern matching, while if-else provides conditional branching based on boolean expressions. Syntax Following is the syntax for a switch statement − switch (expression) { case value1: // code block break; case ...
Read More