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
Programming Articles
Page 105 of 2547
Enum.GetNames in C#
The Enum.GetNames() method in C# retrieves an array of the names of constants in a specified enumeration. This method is useful when you need to dynamically access or display all the values defined in an enum without hardcoding them. Syntax Following is the syntax for the Enum.GetNames() method − public static string[] GetNames(Type enumType) Parameters enumType − The System.Type of the enumeration whose names you want to retrieve. Return Value Returns a string[] array containing the names of the constants in the specified enumeration, ordered by their ...
Read MoreC# into keyword
The into keyword in C# LINQ is used to create intermediate query expressions. It allows you to continue a query after a select or group clause by introducing a new range variable that represents the results of the previous query operation. Syntax Following is the syntax for using the into keyword in LINQ queries − from element in collection select expression into newVariable where condition select finalExpression The into keyword can also be used with group operations − from element in collection group element by key into groupVariable where groupCondition select groupExpression ...
Read MoreWhat are the C++ features missing in C#?
C# is a simple, modern, general-purpose, object-oriented programming language developed by Microsoft within its .NET initiative led by Anders Hejlsberg. While C# and C++ share some similarities, there are several key features present in C++ that are either missing or implemented differently in C#. C++ is a middle-level programming language developed by Bjarne Stroustrup starting in 1979 at Bell Labs. C++ runs on a variety of platforms and provides more direct hardware control compared to C#. Key C++ Features Missing in C# Multiple Inheritance C++ supports multiple inheritance, allowing a class to inherit from multiple base ...
Read MoreHow to check if array contains a duplicate number using C#?
Checking if an array contains duplicate numbers is a common programming task in C#. There are multiple approaches to solve this problem, ranging from simple loops to LINQ methods and hash-based techniques. Using Dictionary to Count Occurrences The dictionary approach counts the frequency of each element in the array. Any element with a count greater than 1 is a duplicate − using System; using System.Collections.Generic; namespace Demo { public class Program { public static void Main(string[] args) { ...
Read MoreC# NullReferenceException
A NullReferenceException is one of the most common runtime exceptions in C#. It occurs when you try to access a member (property, method, or field) of an object reference that is null. When NullReferenceException Occurs This exception is thrown when − You call a method on a null reference You access or modify a property of a null reference You get the length of a null array or string You index into a null array NullReferenceException Flow ...
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 MoreHow do you loop through a C# array?
To loop through an array in C#, you can use several loop types including for, foreach, while, and do...while loops. Each loop provides different ways to iterate through array elements and access their values. The most commonly used loops for arrays are the for loop (when you need index access) and the foreach loop (when you only need element values). Syntax Following is the syntax for different loop types with arrays − // for loop for (int i = 0; i < array.Length; i++) { // access array[i] } // ...
Read MoreSingleton Class in C#
A Singleton class in C# is a design pattern that ensures only one instance of a class can be created throughout the application's lifetime. It provides a global point of access to that instance and is commonly used for logging, database connections, and configuration management. The key principle of the Singleton pattern is to restrict instantiation of a class to a single object by using a private constructor and providing a static method or property to access the instance. Syntax Following is the basic syntax for implementing a Singleton class − public class Singleton { ...
Read MoreCombine two arrays in C#
Combining two arrays in C# can be accomplished using various methods. The most common approaches include using List.AddRange() method, Array.Copy(), or LINQ's Concat() method. Syntax Using List.AddRange() method − var list = new List(); list.AddRange(array1); list.AddRange(array2); T[] combinedArray = list.ToArray(); Using Array.Copy() method − T[] combinedArray = new T[array1.Length + array2.Length]; Array.Copy(array1, 0, combinedArray, 0, array1.Length); Array.Copy(array2, 0, combinedArray, array1.Length, array2.Length); Using LINQ Concat() method − T[] combinedArray = array1.Concat(array2).ToArray(); Using List.AddRange() Method This approach creates a List, adds both arrays using AddRange(), then converts ...
Read MoreC# Convert.ToInt32 Method
The Convert.ToInt32 method in C# is used to convert various data types to a 32-bit signed integer. It is commonly used to convert strings, floating-point numbers, and other numeric types to integers, providing a versatile approach to type conversion. Syntax Following are the most common syntax forms for Convert.ToInt32 − Convert.ToInt32(value); Convert.ToInt32(value, fromBase); Parameters value − The value to convert (string, double, decimal, bool, etc.) fromBase − Optional. The base of the number system (2, 8, 10, or 16) Return Value Returns a 32-bit signed integer equivalent to the ...
Read More