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 844 of 2109
How do you sort an array in C# in ascending order?
In C#, you can sort an array in ascending order using the built-in Array.Sort() method. This method modifies the original array directly and arranges elements from smallest to largest value. Syntax Following is the syntax for sorting an array in ascending order − Array.Sort(arrayName); Parameters arrayName − The array to be sorted. This parameter is required and the array is modified in-place. Using Array.Sort() Method The Array.Sort() method automatically sorts elements in ascending order. Here's how to sort an integer array − using System; ...
Read MoreDifference between Method and Function in C#
In C#, the terms method and function are often used interchangeably, but there is a subtle distinction. A method is a function that belongs to a class or struct, while a function is a more general term for a reusable block of code that performs a specific task. Every C# program has at least one class with a method named Main. Methods are defined within classes and operate on the data and behavior of those classes. Syntax Following is the syntax for defining a method in C# − [access modifier] [return type] MethodName(parameters) { ...
Read MoreWhat is the Item property of SortedList class in C#?
The Item property of the SortedList class in C# gets and sets the value associated with a specific key in the SortedList. It allows you to access and modify elements using the indexer syntax [key], making SortedList operations intuitive and similar to working with arrays or dictionaries. The Item property can also be used to add new elements directly. If the key does not exist, it creates a new key-value pair. If the key already exists, it overwrites the existing value with the new one. Syntax Following is the syntax for using the Item property − ...
Read MoreHow to find minimum between 2 numbers using C#?
Finding the minimum between two numbers in C# can be accomplished using several approaches. The most common methods include using conditional statements like if-else or utilizing built-in methods like Math.Min(). Using if-else Statement The traditional approach uses an if-else statement to compare two numbers and determine the smaller value − using System; class Program { static void Main(string[] args) { int num1 = 50; int num2 = 90; int minNum; ...
Read MoreDifference between C# and Visual C#
C# and Visual C# are essentially the same programming language. C# is the programming language specification, while Visual C# refers to the C# development experience within Microsoft's Visual Studio IDE. Think of Visual C# as the toolset and environment for writing C# code. Microsoft Visual Studio is an Integrated Development Environment (IDE) that provides comprehensive tools for developing applications, web services, and desktop programs. When you use Visual Studio to write C# code, you're using what Microsoft calls "Visual C#" − the C# compiler, IntelliSense, debugging tools, and project templates all integrated together. Key Differences ...
Read MoreWhat is the IsReadOnly property of ArrayList class in C#?
The IsReadOnly property of the ArrayList class in C# returns a boolean value indicating whether the ArrayList is read-only. A read-only ArrayList cannot be modified after creation − you cannot add, remove, or change elements. Syntax Following is the syntax for using the IsReadOnly property − bool isReadOnly = arrayList.IsReadOnly; Return Value The IsReadOnly property returns − true − if the ArrayList is read-only false − if the ArrayList can be modified Using IsReadOnly with Regular ArrayList A regular ArrayList created using the default constructor is always modifiable, ...
Read MoreWhat is the Length property of BitArray class in C#?
The Length property of the BitArray class in C# is used to get or set the number of elements in the BitArray. This property allows you to determine the size of the bit array and also resize it when needed. Syntax Following is the syntax for using the Length property − public int Length { get; set; } Return Value The Length property returns an int value representing the number of elements in the BitArray. Using Length Property to Get BitArray Size You can use the Length property to determine how ...
Read MoreHow to Initialize and Compare Strings in C#?
String initialization and comparison are fundamental operations in C# programming. C# provides multiple ways to initialize strings and several methods to compare them effectively. String Initialization There are several ways to initialize a string in C# − // Direct assignment string str1 = "Hello, World!"; // Using string constructor string str2 = new string("Welcome"); // Empty string initialization string str3 = ""; string str4 = string.Empty; Example using System; class Program { static void Main(string[] args) { ...
Read MoreHow to find maximum between 2 numbers using C#?
Finding the maximum between two numbers in C# can be accomplished using several approaches. The most common methods include using conditional statements, the Math.Max() method, and the ternary operator. Using If-Else Statement The traditional approach uses an if-else statement to compare two numbers and determine which one is larger − using System; class Program { static void Main(string[] args) { int num1 = 50; int num2 = 90; ...
Read MoreHow to create a thread in C#?
Threads are lightweight processes that represent independent execution paths within a program. In C#, threads are created using the Thread class from the System.Threading namespace. Creating threads enables concurrent programming, allowing multiple operations to run simultaneously and improving application efficiency. Modern operating systems use threads to implement concurrent programming, which saves CPU cycles and increases application performance by allowing multiple tasks to execute in parallel. Syntax Following is the basic syntax for creating a thread in C# − Thread threadName = new Thread(methodName); threadName.Start(); You can also use a ThreadStart delegate to wrap ...
Read More