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 846 of 2109
What are Booleans types in C#?
The bool type in C# represents Boolean values and can store only two possible values: true and false. The bool keyword is an alias for the System.Boolean structure in the .NET framework. Boolean variables are commonly used in conditional statements, loops, and logical operations to control program flow based on true/false conditions. Syntax Following is the syntax for declaring Boolean variables − bool variableName = true; // or false bool variableName; // defaults to false Basic Boolean Declaration and Assignment Example ...
Read MoreHow to use StringBuilder in C#?
The StringBuilder class in C# is designed for efficient string manipulation when you need to perform multiple operations like appending, inserting, or replacing characters. Unlike regular strings, which are immutable and create new objects for every modification, StringBuilder maintains a mutable buffer that can be expanded without creating new objects in memory. Syntax Following is the syntax to initialize a StringBuilder − StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder(string value); StringBuilder sb = new StringBuilder(int capacity); StringBuilder sb = new StringBuilder(string value, int capacity); Key Advantages of StringBuilder Mutable ...
Read MoreHow to use the ?: conditional operator in C#?
The conditional operator (also called the ternary operator) is represented by the symbol ?:. It provides a concise way to write simple if-else statements in a single expression. The operator has right-to-left associativity and evaluates a boolean condition to return one of two possible values. Syntax Following is the syntax for the conditional operator − condition ? value_if_true : value_if_false Where: condition is an expression that evaluates to a boolean value value_if_true is returned if the condition is true value_if_false is returned if the condition is false How It Works ...
Read MoreHow to use the GetLowerBound method of array class in C#
The GetLowerBound() method of the Array class in C# returns the lower bound of the specified dimension in an array. For most arrays in C#, the lower bound is typically 0, but this method becomes useful when working with arrays that have custom bounds or multi-dimensional arrays. Syntax Following is the syntax for the GetLowerBound() method − public int GetLowerBound(int dimension); Parameters dimension − A zero-based dimension of the array whose lower bound needs to be found. Return Value Returns an integer representing the lower bound of the specified ...
Read MoreHow to sort a list in C#?
Sorting a list in C# can be accomplished using several methods. The List class provides the Sort() method for in-place sorting, while LINQ offers additional sorting capabilities. This article demonstrates various approaches to sort lists in ascending and descending order. Syntax Following is the syntax for the basic Sort() method − list.Sort(); Following is the syntax for sorting with a custom comparer − list.Sort((x, y) => y.CompareTo(x)); // descending order Using List.Sort() Method The Sort() method sorts the elements in the entire list using the default comparer for the ...
Read MoreHow to use the GetType method of array class in C#?
The GetType() method in C# is inherited from the Object class and returns the exact runtime type of the current instance. When used with arrays, it provides information about the array's type, including its element type and dimensions. Syntax Following is the syntax for using the GetType() method − Type type = arrayInstance.GetType(); Return Value The method returns a Type object that represents the exact runtime type of the current instance. Using GetType() with Arrays When applied to arrays, GetType() returns the array type, which includes information about the element type ...
Read MoreHow to use the GetValue() method of array class in C#?
The GetValue() method of the Array class in C# retrieves the value at a specified position in a multi-dimensional or single-dimensional array. This method is particularly useful when working with arrays created using Array.CreateInstance(), as it provides a generic way to access array elements regardless of the array's underlying type. Syntax Following is the syntax for using GetValue() with different array dimensions − // For single-dimensional array object value = array.GetValue(index); // For multi-dimensional array object value = array.GetValue(index1, index2); object value = array.GetValue(index1, index2, index3); Parameters index − A 32-bit ...
Read MoreHow to use the Main() method in C#?
The Main() method in C# is the entry point of any C# application. It is a static method that runs when the program starts, without requiring an instance of the class to be created. The Main() method defines what the class does when executed and can instantiate other objects and variables. Syntax Following are the valid signatures for the Main() method − static void Main() static void Main(string[] args) static int Main() static int Main(string[] args) Parameters The Main() method signature includes the following components − static − The method ...
Read MoreHow to use the return statement in C#?
The return statement in C# is used to exit a method and optionally return a value to the caller. When a method contains a return statement, the program control immediately transfers back to the calling method along with the specified return value. Syntax Following is the syntax for using the return statement − return; // For void methods (no value returned) return expression; // For methods that return a value Using Return Statement with Value Types When a method has a return type other than void, it must return a ...
Read MoreHow to use the ToString() method of array in C#?
The ToString() method in C# returns a string representation of an object. For arrays, the default ToString() method returns the type name rather than the array contents. However, ToString() is commonly used with array properties and methods that return numeric values. Syntax Following is the syntax for using ToString() with array methods − arrayObject.Method().ToString() For converting array elements to strings − array[index].ToString() Using ToString() with Array Properties The ToString() method is useful when converting array properties like bounds and length to string format for display purposes − ...
Read More