Chandu yadav

Chandu yadav

810 Articles Published

Articles by Chandu yadav

Page 7 of 81

What are key-based I/O collections in C#?

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 261 Views

Key-based I/O collections in C# are collections that store data as key-value pairs, where you can access values using their associated keys. The primary example of this is the SortedList class, which maintains elements in sorted order based on the keys. Syntax Following is the syntax for declaring a generic SortedList − SortedList listName = new SortedList(); Following is the syntax for adding key-value pairs − listName.Add(key, value); listName[key] = value; // alternative syntax Key Features of SortedList Stores key-value pairs sorted by keys in ascending order ...

Read More

Implicit conversion from 8-bit signed integer (SByte) to Decimal in C#

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 301 Views

SByte represents an 8-bit signed integer with values ranging from -128 to 127. C# allows implicit conversion from sbyte to decimal because this conversion is always safe and does not result in data loss. Syntax Following is the syntax for implicit conversion from sbyte to decimal − sbyte sbyteValue = value; decimal decimalValue = sbyteValue; // implicit conversion How It Works The conversion happens automatically without requiring explicit casting because decimal can represent all possible sbyte values without precision loss. The 8-bit signed integer is widened to fit into the 128-bit decimal ...

Read More

C# program to multiply two matrices

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

Matrix multiplication is a mathematical operation that combines two matrices to produce a third matrix. This operation is only possible when the number of columns in the first matrix equals the number of rows in the second matrix. If matrix A has dimensions m×n and matrix B has dimensions n×p, the resulting matrix C will have dimensions m×p. Matrix Multiplication Rule Matrix A m × n 2 × 3 × Matrix B n × p ...

Read More

Optional property in a C# class

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

An optional property in a C# class is a property that can have a null value without causing runtime errors. Properties whose CLR types cannot hold null values (like value types) cannot be configured as optional unless they are made nullable using the ? operator. Optional properties are commonly implemented using nullable reference types, default values, or custom attributes to indicate that the property is not required to have a value. Syntax Following is the syntax for declaring nullable properties − public string? PropertyName { get; set; } // Nullable reference type ...

Read More

What are accessors of properties in C#?

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 948 Views

Properties are an extension of fields and are accessed using the same syntax. They use accessors through which the values of the private fields can be read, written or manipulated. The accessor of a property contains the executable statements that help in getting (reading or computing) or setting (writing) the property. Properties provide a controlled way to access class fields while maintaining encapsulation. Syntax Following is the syntax for property accessors in C# − public datatype PropertyName { get { return fieldName; } ...

Read More

C# program to merge two Dictionaries

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

Merging dictionaries in C# involves combining two or more Dictionary objects into one. This can be useful when you need to consolidate data from different sources or combine configuration settings. There are several approaches to merge dictionaries, each with different behaviors for handling duplicate keys. Syntax Following is the syntax for creating dictionaries − Dictionary dict = new Dictionary(); Following is the syntax for adding elements − dict.Add(key, value); dict[key] = value; // overwrites if key exists Using HashSet to Merge Keys Only This approach merges only the ...

Read More

Ways to print escape characters in C#

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

The following are the escape characters in C# and the display column suggests how to use and print them in C# − Escape Character Description Pattern Display \a Matches a bell character, \u0007. \a "\u0007" in "Warning!" + '\u0007' \b In a character class, matches a backspace, \u0008. [\b]{3, } "\b\b\b\b" in "\b\b\b\b" \t Matches a tab, \u0009. (\w+)\t "Name\t", "Addr\t" in "Name\tAddr\t" \r Matches a carriage return, \u000D. (\r is not equivalent to the newline character, .) \r(\w+) "\rHello" in "\r\HelloWorld." \v Matches ...

Read More

How to negate the positive elements of an integer array in C#?

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 465 Views

Negating the positive elements of an integer array means converting all positive values to their negative counterparts while leaving negative and zero values unchanged. This operation is useful in various mathematical computations and data processing scenarios. Syntax Following is the basic syntax to check and negate positive elements − if (arr[i] > 0) arr[i] = -arr[i]; A complete loop structure to process all array elements − for (int i = 0; i < arr.Length; i++) { if (arr[i] > 0) ...

Read More

Private Methods in C#

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

Private methods in C# can only be accessed within the class where they are defined. They use the private access modifier to restrict visibility and are commonly used for internal helper functionality that should not be exposed to external code. The private access specifier allows a class to hide its member variables and member functions from other functions and objects. Only methods within the same class can access private members, providing encapsulation and data hiding. Syntax Following is the syntax for declaring a private method − private returnType MethodName(parameters) { // method ...

Read More

What are Base and Derived Classes in C#?

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 350 Views

In C# object-oriented programming, inheritance allows you to create new classes based on existing ones. A base class (also called parent class) is the original class that provides common properties and methods. A derived class (also called child class) inherits from the base class and can access its members while adding its own specific functionality. The derived class automatically inherits all accessible members from the base class, including fields, properties, and methods, promoting code reusability and establishing an "is-a" relationship. Syntax Following is the syntax for creating a derived class in C# − class BaseClass ...

Read More
Showing 61–70 of 810 articles
« Prev 1 5 6 7 8 9 81 Next »
Advertisements