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 768 of 2109
What are user defined data types in C#?
User-defined data types in C# allow developers to create custom types beyond the built-in primitive types. The main user-defined data types in C# are structures, enumerations, classes, interfaces, and delegates. This article focuses on structures and enumerations as fundamental user-defined types. Structure In C#, a structure is a value type data type that helps you group related data of various types into a single unit. The struct keyword is used for creating a structure. Syntax public struct StructName { // fields, properties, methods, constructors public dataType field1; ...
Read MoreWhat is aggregation in C#?
Aggregation in C# represents a has-a relationship between objects where one class contains or uses another class. In aggregation, the contained object can exist independently of the container object, making it a weak association. For example, an Employee has an Address, and a Department has multiple Employees. The key characteristic of aggregation is that when the container object is destroyed, the contained objects continue to exist independently. Syntax Following is the syntax for implementing aggregation in C# − public class ContainerClass { private ContainedClass containedObject; ...
Read MoreWhat is finally statement in C#?
The finally statement in C# is used to execute a given set of statements, whether an exception is thrown or not thrown. For example, if you open a file, it must be closed whether an exception is raised or not. The error handling blocks are implemented using the try, catch, and finally keywords. The finally block is guaranteed to execute, making it ideal for cleanup operations like closing files, database connections, or releasing resources. Syntax Following is the syntax for the finally statement − try { // code that might throw an ...
Read MoreWhat does Array.IsFixedSize property of array class do in C# ?
The IsFixedSize property of the ArrayList class is used to determine whether an ArrayList has a fixed size. When IsFixedSize returns true, you cannot add or remove elements, but you can still modify existing elements. When it returns false, the ArrayList can grow or shrink dynamically. Regular ArrayLists created with the default constructor always return false for IsFixedSize because they can dynamically resize. However, you can create fixed-size wrappers using ArrayList.FixedSize() method. Syntax Following is the syntax to check the IsFixedSize property − bool isFixed = arrayList.IsFixedSize; Following is the syntax to create ...
Read MoreWhat is overloading in C#?
C# provides two techniques to implement static polymorphism − Function overloading Operator overloading Function Overloading Function overloading in C# allows multiple methods with the same name but different parameters within the same class. The compiler determines which method to call based on the number, types, and order of arguments passed. Syntax Following is the syntax for function overloading − public returnType MethodName(parameter1) { } public returnType MethodName(parameter1, parameter2) { } public returnType MethodName(differentType parameter) { } Method Overloading Resolution Add(int, ...
Read MoreWhat does Array.Length property of array class do in C#?
The Array.Length property in C# is used to get the total number of elements in an array. This property returns an integer value representing the array's size, which is essential for array manipulation and iteration. Syntax Following is the syntax for using the Array.Length property − int length = arrayName.Length; Return Value The Length property returns an int value representing the total number of elements in the array. Using Array.Length with Array.CreateInstance The following example demonstrates how to use Array.Length with dynamically created arrays − using System; class ...
Read MoreWhat does Array.LongLength property of array class do in C#?
The Array.LongLength property in C# gets a 64-bit integer (long) that represents the total number of elements in all dimensions of an array. This property is particularly useful when working with very large arrays that might exceed the range of a 32-bit integer. Syntax Following is the syntax for using the LongLength property − long totalElements = arrayName.LongLength; Return Value The property returns a long value representing the total number of elements across all dimensions of the array. Single-Dimensional Array Example For a single-dimensional array, LongLength returns the same value as ...
Read MoreHow to calculate the power exponent value using C#?
To calculate the power exponent value in C#, use the Math.Pow() method from the System namespace. This method raises a number to a specified power and returns the result as a double. Syntax Following is the syntax for the Math.Pow() method − public static double Pow(double x, double y) Parameters x − The base number (of type double). y − The exponent (of type double). Return Value Returns a double value representing x raised to the power of y (xy). Using Math.Pow() with Integers ...
Read MoreFibonacci Series in C#
The Fibonacci series is a sequence of numbers where each number is the sum of the two preceding numbers. The series typically starts with 0 and 1, producing the sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, and so on. In C#, there are multiple ways to generate the Fibonacci series, including iterative and recursive approaches. Fibonacci Series Pattern 0 1 1 2 3 ...
Read MoreWhat is the use of 'new' keyword in C#?
The new keyword in C# serves multiple important purposes. It is primarily used to create new instances of classes, allocate memory for arrays, and hide inherited members from base classes. Syntax Following is the syntax for creating object instances using new − ClassName objectName = new ClassName(); Following is the syntax for creating arrays using new − dataType[] arrayName = new dataType[size]; Following is the syntax for hiding base class members using new − public new void MethodName() { // hides the base class method ...
Read More