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 93 of 196
What 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 MoreWhat is the Values property of Hashtable class in C#?
The Values property of the Hashtable class in C# gets an ICollection containing all the values stored in the Hashtable. This property provides a way to access all values without needing to know their corresponding keys. Syntax Following is the syntax for using the Values property − public virtual ICollection Values { get; } To iterate through the values − foreach (object value in hashtable.Values) { // process each value } Return Value The Values property returns an ICollection object that contains all the values ...
Read MoreHow to calculate power of three using C#?
Calculating the power of a number in C# can be done using recursion, iteration, or built-in methods. This article demonstrates how to calculate powers with a focus on raising numbers to the power of 3, though the methods work for any exponent. Syntax Following is the syntax for a recursive power function − static long power(int baseNumber, int exponent) { if (exponent != 0) { return (baseNumber * power(baseNumber, exponent - 1)); } return 1; } ...
Read More