Articles on Trending Technologies

Technical articles with clear explanations and examples

How to parse a string into a nullable int in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 6K+ Views

Parsing a string into a nullable int in C# allows you to handle cases where the string might not represent a valid integer. A nullable int (int?) can store either an integer value or null, making it ideal for scenarios where conversion might fail. C# provides several approaches to parse strings into nullable integers, from extension methods to built-in parsing techniques that handle invalid input gracefully. Syntax Following is the syntax for declaring a nullable int − int? nullableInt = null; int? nullableInt = 42; Following is the syntax for parsing using int.TryParse() ...

Read More

How to change the CursorTop of the Console in C#?

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 327 Views

The Console.CursorTop property in C# gets or sets the row position of the cursor within the console window. This property allows you to control the vertical position where text will be displayed, enabling you to create formatted console output, menus, or position text at specific locations. Syntax Following is the syntax for using Console.CursorTop − // Get current cursor top position int currentTop = Console.CursorTop; // Set cursor top position Console.CursorTop = value; Parameters The Console.CursorTop property accepts an integer value representing the row position (0-based) where the cursor should be positioned. ...

Read More

SByte.ToString() Method in C# with Examples

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 524 Views

The SByte.ToString() method in C# is used to convert the numeric value of a signed byte to its equivalent string representation. The sbyte data type represents 8-bit signed integers with values ranging from -128 to 127. Syntax Following is the syntax for the basic ToString() method − public override string ToString(); Following is the syntax for ToString() with format provider − public string ToString(IFormatProvider provider); public string ToString(string format); public string ToString(string format, IFormatProvider provider); Return Value The method returns a string that represents the value of the current ...

Read More

Add key and value into StringDictionary in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 318 Views

The StringDictionary class in C# provides a specialized collection for storing string key-value pairs. It is case-insensitive, meaning keys are automatically converted to lowercase when added. The Add() method is used to insert new key-value pairs into the collection. Syntax Following is the syntax for adding key-value pairs to a StringDictionary − StringDictionary dictionary = new StringDictionary(); dictionary.Add(key, value); Parameters key − The key to add to the StringDictionary (string type). value − The value associated with the key (string type). Key Rules ...

Read More

Get the number of key/value pairs in the Dictionary in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 762 Views

The Dictionary class in C# provides the Count property to get the number of key/value pairs stored in the dictionary. This property returns an integer representing the total count of elements currently in the dictionary. Syntax Following is the syntax for using the Count property − Dictionary dictionary = new Dictionary(); int count = dictionary.Count; Parameters The Count property does not take any parameters. It is a read-only property that returns the current number of key/value pairs in the dictionary. Return Value The Count property returns an int value representing the ...

Read More

How do you give a C# Auto-Property a default value?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 2K+ Views

In C#, auto-properties provide a shorthand way to declare properties without explicitly writing getter and setter methods. Setting default values for auto-properties can be done in two main ways: using constructor initialization (available in all C# versions) or using property initializers (introduced in C# 6.0). Syntax Constructor initialization syntax (C# 5.0 and earlier) − public class ClassName { public PropertyType PropertyName { get; set; } public ClassName() { PropertyName = defaultValue; ...

Read More

How to get all the files, sub files and their size inside a directory in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 2K+ Views

To get all files and subdirectories within a directory in C#, the Directory.GetFiles method provides a comprehensive solution. This method returns the names of all files (including their full paths) that match a specified search pattern and can optionally search through subdirectories. The FileInfo class allows you to retrieve detailed information about each file, including its size, creation date, and other properties. Syntax Following is the syntax for using Directory.GetFiles − string[] files = Directory.GetFiles(path, searchPattern, searchOption); Parameters path − The directory path to search searchPattern − The search pattern (e.g., ...

Read More

SortedDictionary.Keys Property in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 364 Views

The SortedDictionary.Keys property in C# returns a collection containing all the keys in the SortedDictionary. The keys are returned in sorted order based on the comparer used by the SortedDictionary. Syntax Following is the syntax for the Keys property − public SortedDictionary.KeyCollection Keys { get; } Return Value The Keys property returns a SortedDictionary.KeyCollection containing all the keys in the SortedDictionary. The collection is read-only and reflects changes made to the underlying dictionary. Using Keys Property with Integer Keys Example using System; using System.Collections.Generic; public class Demo { ...

Read More

Getting the keys in a SortedList object C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 186 Views

The SortedList class in C# stores key-value pairs sorted by the keys. To retrieve all the keys from a SortedList object, you use the Keys property, which returns an ICollection containing all the keys in sorted order. Syntax Following is the syntax for getting keys from a SortedList − SortedList sortedList = new SortedList(); ICollection keys = sortedList.Keys; The Keys property returns an ICollection that can be iterated using a foreach loop − foreach(string key in keys) { Console.WriteLine(key); } Using Keys Property with String Keys ...

Read More

ConvertDecimal to equivalent 32-bit unsigned integer in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 593 Views

To convert the value of the specified decimal to the equivalent 32-bit unsigned integer, C# provides the Decimal.ToUInt32() method. This method truncates the fractional part and returns only the whole number portion as a uint value. Syntax Following is the syntax for converting decimal to uint − public static uint ToUInt32(decimal value); Parameters value − The decimal number to be converted to a 32-bit unsigned integer. Return Value Returns a 32-bit unsigned integer (uint) equivalent to the specified decimal value. The fractional part is truncated, not rounded. Using ...

Read More
Showing 9981–9990 of 61,299 articles
Advertisements