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 by Chandu yadav
Page 7 of 81
What are key-based I/O collections in C#?
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 MoreImplicit conversion from 8-bit signed integer (SByte) to Decimal in C#
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 MoreC# program to multiply two matrices
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 MoreOptional property in a C# class
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 MoreWhat are accessors of properties in C#?
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 MoreC# program to merge two Dictionaries
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 MoreWays to print escape characters in C#
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 MoreHow to negate the positive elements of an integer array in C#?
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 MorePrivate Methods in C#
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 MoreWhat are Base and Derived Classes in C#?
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