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
Articles on Trending Technologies
Technical articles with clear explanations and examples
Represent exact representation of no time in C#
The TimeSpan.Zero property in C# represents the exact representation of no time, which displays as 00:00:00. This is a static readonly field that provides a convenient way to initialize or compare TimeSpan values when you need to represent zero duration. Syntax Following is the syntax for using TimeSpan.Zero − TimeSpan timespan = TimeSpan.Zero; You can also use it for comparison operations − if (timespan == TimeSpan.Zero) { // timespan represents no time } Using TimeSpan.Zero for Initialization The most common use of TimeSpan.Zero is to initialize ...
Read MoreClear a Hashtable in C#
The Clear() method in C# is used to remove all key-value pairs from a Hashtable. This method provides an efficient way to empty the entire Hashtable in a single operation, resetting its count to zero while maintaining the original capacity. Syntax Following is the syntax for the Clear()
Read MoreChar.TryParse() Method in C#
The Char.TryParse() method in C# is used to convert a string representation to its equivalent Unicode character. This method returns true if the conversion succeeds, or false if it fails, making it a safe alternative to Char.Parse() which throws exceptions on invalid input. The method only succeeds if the input string contains exactly one character. Multi-character strings, empty strings, or null values will cause the method to return false. Syntax Following is the syntax for the Char.TryParse() method − public static bool TryParse(string str, out char result); Parameters str − ...
Read MoreDateTime.ToOADate() Method in C#
The DateTime.ToOADate() method in C# is used to convert a DateTime instance to its equivalent OLE Automation date. OLE Automation dates are represented as double-precision floating-point numbers where the integer part represents the number of days since December 30, 1899, and the fractional part represents the time of day. Syntax Following is the syntax − public double ToOADate(); Return Value Returns a double representing the OLE Automation date equivalent of the current DateTime instance. How It Works OLE Automation dates use a specific format where: Integer part: Number ...
Read MoreAssociation, Composition and Aggregation in C#
In C#, object-oriented programming relies on relationships between classes to model real-world scenarios. Three fundamental types of relationships are Association, Composition, and Aggregation. These relationships define how objects interact and depend on each other. Object Relationships in C# Association "Uses-a" Loose coupling Aggregation "Has-a" Weak ownership Composition "Part-of" Strong ownership ...
Read MoreFormat TimeSpan in C#
The TimeSpan class in C# represents a time interval and provides several formatting options to display time in different formats. You can format a TimeSpan using standard format strings, custom format strings, or the ToString() method with format specifiers. Syntax Following is the syntax for formatting a TimeSpan using custom format strings − timeSpan.ToString("format_string") Following is the syntax for formatting using composite formatting − string.Format("{0:format_string}", timeSpan) Using Standard Format Strings TimeSpan supports standard format strings like "c" (constant format), "g" (general short), and "G" (general long) − ...
Read MoreAdd key-value pair in C# Dictionary
To add key-value pairs in C# Dictionary, you can use several methods. The Dictionary class provides multiple ways to insert elements, each with its own advantages for different scenarios. Syntax Following are the main syntaxes for adding key-value pairs to a Dictionary − // Using Add() method with separate key and value dictionary.Add(key, value); // Using Add() method with KeyValuePair dictionary.Add(new KeyValuePair(key, value)); // Using indexer syntax dictionary[key] = value; Using Add() Method with Key and Value The most common approach is using the Add() method with separate key and value ...
Read MoreWhat are mixed arrays in C#?
Mixed arrays in C# refer to arrays that can store elements of different data types. They were historically used as a combination of multi-dimensional arrays and jagged arrays, but this terminology is largely obsolete in modern C#. Instead, we use object[] arrays or collections to achieve similar functionality. Note − The traditional "mixed arrays" concept became obsolete after .NET 4.0, as modern C# provides better alternatives like generic collections and tuples. Syntax Following is the syntax for creating an array that can hold mixed data types − object[] arrayName = new object[] { value1, value2, ...
Read MoreSwap two Strings without using temp variable in C#
To swap two strings without using a temporary variable in C#, you can use string concatenation and the Substring() method. This technique works by combining both strings into one, then extracting the original values in reverse order. Algorithm The swapping process follows these three steps − Step 1: Append the second string to the first string. Step 2: Extract the original first string from the beginning and assign it to the second string variable. Step 3: Extract the original second string from the remaining part and assign it to the first string variable. ...
Read MoreStopwatch class in C#
The Stopwatch class in C# is used to measure elapsed time with high precision. It provides accurate timing measurements for performance monitoring and benchmarking applications. The class is found in the System.Diagnostics namespace. Syntax Following is the syntax for creating and starting a Stopwatch − Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); Alternatively, you can create and start in one line − Stopwatch stopwatch = Stopwatch.StartNew(); Key Properties and Methods Property/Method Description Start() Starts measuring elapsed time Stop() Stops measuring elapsed ...
Read More