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
Csharp Articles
Page 163 of 196
Tuple Rest Property in C#
The Rest property in C# tuples allows you to create tuples with eight or more elements by nesting additional tuple objects. When a tuple has more than seven elements, the eighth and subsequent elements are stored in the Rest property as a nested tuple. Syntax The general structure for an 8-element tuple using the Rest property is − Tuple Where TRest is another tuple type containing the remaining elements. You can create such tuples using Tuple.Create() − var myTuple = Tuple.Create(item1, item2, item3, item4, item5, item6, item7, item8); How the ...
Read MoreC# Program to get the type of the specified Enumeration
Use the GetType() method to get the type of the specified enumeration in C#. This method returns a Type object that represents the actual enumeration type, which is useful for reflection, debugging, and type checking operations. When working with enumeration values, you can retrieve both the enumeration type and its underlying type using built-in methods provided by the Enum class and Type class. Syntax Following is the syntax for getting the type of an enumeration − Type enumType = enumValue.GetType(); To get the underlying type of an enumeration − Type underlyingType ...
Read MoreC# Enum GetValues Method
The Enum.GetValues() method in C# retrieves an array containing the values of all constants in a specified enumeration. This method is useful when you need to iterate through all enum values dynamically or perform operations on the entire set of enum values. Syntax Following is the syntax for the Enum.GetValues() method − public static Array GetValues(Type enumType) Parameters enumType − The Type of the enumeration whose values you want to retrieve. Return Value Returns an Array containing the values of the constants in the specified enumeration. Using GetValues() ...
Read MoreComplex Numbers in C#
A complex number in C# consists of two components: a real part and an imaginary part. For example, in the complex number 7+5i, the real part is 7 and the imaginary part is 5 (the coefficient of i). C# allows you to create custom data structures to represent complex numbers using struct and implement mathematical operations using operator overloading. Syntax Following is the syntax for creating a complex number structure − public struct Complex { public double real; public double imaginary; public ...
Read MoreCompound assignment operators in C#
Compound assignment operators in C# provide a shorter syntax to perform an operation and assign the result back to the same variable. These operators combine arithmetic, bitwise, or shift operations with assignment in a single step. For example, x += 5 is equivalent to x = x + 5, but more concise and readable. Syntax The general syntax for compound assignment operators is − variable operator= value; This is equivalent to − variable = variable operator value; Types of Compound Assignment Operators Operator Name Equivalent ...
Read MoreConstructors in C#
A constructor in C# is a special method that gets invoked automatically when an object is created. The constructor has the same name as the class and is used to initialize the object's state. Constructors do not have a return type, not even void. Syntax Following is the basic syntax for declaring a constructor − public class ClassName { public ClassName() { // constructor body } } Types of Constructors C# supports several types of constructors − Default ...
Read MoreDefault constructor in C#
A default constructor in C# is a constructor that takes no parameters. When you create an object of a class, the constructor is automatically invoked. The constructor has the same name as the class and is used to initialize the object. If you don't explicitly define any constructor in your class, C# automatically provides a default constructor. However, if you define any parameterized constructor, you must explicitly define the default constructor if you want to use it. Syntax Following is the syntax for declaring a default constructor − public class ClassName { ...
Read MoreDifference between Abstract Class and Interface in C#
Both abstract classes and interfaces in C# define contracts for derived classes to implement, but they serve different purposes and have distinct characteristics. An interface defines a contract with method signatures that implementing classes must provide, while an abstract class can provide both abstract methods and concrete implementations that derived classes inherit. Understanding the key differences helps you choose the right approach for your object-oriented design needs. Syntax Following is the syntax for declaring an interface − public interface IInterfaceName { void Method1(); int Property1 { get; ...
Read MoreDifference between Boxing and Unboxing in C#
Boxing converts a value type to an object type, whereas unboxing converts an object type back to the value type. These operations are fundamental concepts in C# that involve moving data between the stack and heap memory. Boxing occurs implicitly when you assign a value type to an object variable, while unboxing requires explicit casting and can throw exceptions if the types don't match. Syntax Following is the syntax for boxing (implicit conversion) − object boxedValue = valueType; Following is the syntax for unboxing (explicit conversion) − ValueType unboxedValue = (ValueType)boxedObject; ...
Read MoreDifferences between C++ and C#
C++ is a statically typed, compiled, general-purpose, case-sensitive programming language that supports procedural, object-oriented, and generic programming paradigms. It is regarded as a middle-level language because it combines both high-level and low-level language features. C# is a simple, modern, general-purpose, object-oriented programming language developed by Microsoft within its .NET initiative, led by Anders Hejlsberg. Both languages share some similarities but differ significantly in design philosophy and implementation. Key Differences Between C++ and C# Memory Management C++ uses manual memory management where developers must explicitly allocate and deallocate memory using new and delete operators. C# features automatic ...
Read More