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
Server Side Programming Articles
Page 779 of 2109
What is a copy constructor in C#?
A copy constructor in C# creates a new object by copying variables from another object of the same class. It provides a way to initialize a new object with the values of an existing object, creating a separate copy rather than a reference to the original object. Syntax Following is the syntax for creating a copy constructor − public ClassName(ClassName obj) { this.field1 = obj.field1; this.field2 = obj.field2; // copy other fields } How Copy Constructor Works A copy constructor takes an object of ...
Read MoreWhat is a sealed class in C#?
A sealed class in C# is a class that cannot be inherited by other classes. When you declare a class as sealed, it prevents any other class from deriving from it. The sealed keyword can also be applied to methods to prevent them from being overridden in further derived classes. Sealed classes are useful when you want to restrict inheritance for security, performance, or design reasons. Common examples include the string class and many value types in .NET Framework. Syntax Following is the syntax for declaring a sealed class − public sealed class ClassName { ...
Read MoreWhat is a static class in C#?
A static class in C# is a class that cannot be instantiated and can only contain static members. Static classes are implicitly sealed, meaning they cannot be inherited, and they cannot contain instance constructors or non-static members. Static classes are useful for grouping related utility methods and constants that don't require object instantiation. They are loaded automatically by the .NET runtime when first referenced. Syntax Following is the syntax for declaring a static class − public static class ClassName { public static ReturnType MethodName() { ...
Read MoreWhat is a static constructor in C#?
A static constructor is a special constructor declared using the static modifier. It is the first block of code executed when a class is accessed for the first time. A static constructor executes only once during the entire lifetime of the application, regardless of how many instances of the class are created. Static constructors are primarily used to initialize static fields or perform one-time setup operations for a class. Syntax Following is the syntax for declaring a static constructor − static ClassName() { // initialization code } Key Rules of ...
Read MoreC# object serialization
Object serialization in C# is the process of converting an object into a stream of bytes for storage or transmission. The serialized data can be saved to files, databases, or sent over a network, and later deserialized back into objects. C# provides several approaches for serialization, including binary serialization, XML serialization, and JSON serialization. Binary serialization preserves the complete object state and type information. Syntax For binary serialization using BinaryFormatter − [Serializable] public class ClassName { // class members } BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, objectInstance); For deserialization ...
Read MoreHow to access elements from multi-dimensional array in C#?
To access elements from a multi-dimensional array in C#, you specify indices for each dimension using square brackets with comma-separated values. For example, a[2, 1] accesses the element at row 3, column 2 (using zero-based indexing). Syntax Following is the syntax for accessing elements from a multi-dimensional array − arrayName[index1, index2, ...indexN] For a 2D array, you use two indices − int element = array[rowIndex, columnIndex]; Understanding Array Indexing Multi-dimensional arrays use zero-based indexing, meaning the first element is at index [0, 0]. Consider this 4×2 array structure − ...
Read MoreHow to convert Lower case to Upper Case using C#?
To convert lowercase to uppercase in C#, use the ToUpper() method. This method converts all lowercase characters in a string to their uppercase equivalents and returns a new string without modifying the original string. Syntax Following is the syntax for the ToUpper() method − string.ToUpper() string.ToUpper(CultureInfo) Parameters CultureInfo (optional) − Specifies the culture-specific formatting information. If not provided, the current culture is used. Return Value The ToUpper() method returns a new string with all lowercase characters converted to uppercase. The original string remains unchanged. Using ToUpper() Method ...
Read MoreValue parameters vs Reference parameters vs Output Parameters in C#
In C#, there are three ways to pass parameters to methods: value parameters, reference parameters, and output parameters. Each mechanism behaves differently in terms of how data is passed and whether changes affect the original variables. Syntax Following are the syntax forms for the three parameter types − // Value parameter (default) public void Method(int value) { } // Reference parameter public void Method(ref int value) { } // Output parameter public void Method(out int value) { } Value Parameters Value parameters copy the actual value of an argument into the ...
Read MoreHow to convert Trigonometric Angles in Radians using C#?
To convert trigonometric angles from degrees to radians in C#, multiply the degree value by Math.PI/180. Most trigonometric functions in C# expect angles in radians, so this conversion is essential for accurate calculations. Syntax Following is the syntax for converting degrees to radians − double radians = degrees * (Math.PI / 180.0); Following is the syntax for converting radians to degrees − double degrees = radians * (180.0 / Math.PI); Converting Degrees to Radians Example The following example shows how to properly convert degrees to radians before using ...
Read MoreHow to access elements from a rectangular array in C#?
To access elements from a rectangular array in C#, you need to specify the row and column indices using square brackets. Multi-dimensional arrays are also called rectangular arrays because they form a rectangular structure with fixed dimensions. Syntax Following is the syntax for accessing elements in a rectangular array − dataType[, ] arrayName = new dataType[rows, columns]; arrayName[rowIndex, columnIndex] = value; To retrieve an element − dataType element = arrayName[rowIndex, columnIndex]; Rectangular Array Structure Columns 0 1 2 ...
Read More