Programming Articles

Page 814 of 2547

Char.TryParse() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 520 Views

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 More

DateTime.ToOADate() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 856 Views

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 More

Association, Composition and Aggregation in C#

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

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 More

Format TimeSpan in C#

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

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 More

Add key-value pair in C# Dictionary

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 29K+ Views

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 More

What are mixed arrays in C#?

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

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 More

Swap two Strings without using temp variable in C#

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

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 More

Stopwatch class in C#

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

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

How to use the ?: conditional operator in C#?

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

The conditional operator (also called the ternary operator) is represented by the symbol ?:. It provides a concise way to write simple if-else statements in a single expression. The operator has right-to-left associativity and evaluates a boolean condition to return one of two possible values. Syntax Following is the syntax for the conditional operator − condition ? value_if_true : value_if_false Where: condition is an expression that evaluates to a boolean value value_if_true is returned if the condition is true value_if_false is returned if the condition is false How It Works ...

Read More

Dictionary.Count Property in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 572 Views

The Dictionary.Count property in C# gets the number of key/value pairs contained in the Dictionary. This property is read-only and provides an efficient way to determine the size of your dictionary collection. Syntax public int Count { get; } Return Value The property returns an int representing the total number of key/value pairs in the dictionary. The count is automatically updated when items are added or removed. Using Dictionary.Count Property Basic Usage Example The following example demonstrates how to use the Count property to track dictionary size − using ...

Read More
Showing 8131–8140 of 25,466 articles
« Prev 1 812 813 814 815 816 2547 Next »
Advertisements