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
Articles on Trending Technologies
Technical articles with clear explanations and examples
Math Class Fields with Examples in C#
The Math class in C# provides essential mathematical constants through predefined fields. The two most commonly used fields are Math.E (Euler's number) and Math.PI (pi), which represent fundamental mathematical constants used in various calculations. These fields are declared as public const double, making them accessible throughout your application without needing to instantiate the Math class. Math.E Field The Math.E field represents Euler's number, which is the natural logarithmic base. This constant is approximately equal to 2.718281828 and is frequently used in exponential and logarithmic calculations. Syntax public const double E = 2.71828182845905; ...
Read MoreHow to determine if the string has all unique characters using C#?
To determine if a string has all unique characters, you need to check if any character appears more than once. This can be accomplished using several approaches in C#, from simple nested loops to more efficient data structures like HashSet. Using Nested Loop Approach The basic approach involves comparing each character with every other character in the string − using System; class Program { public static bool HasUniqueCharacters(string val) { for (int i = 0; i < val.Length - 1; i++) { ...
Read MoreBool Array in C#
A bool array in C# is used to store multiple boolean values (true and false) in a single collection. Boolean arrays are useful for tracking states, flags, or conditions across multiple elements. Syntax Following are the different ways to declare and initialize a bool array − // Declaration with size bool[] arrayName = new bool[size]; // Declaration with initialization bool[] arrayName = {true, false, true}; // Using new keyword with values bool[] arrayName = new bool[] {true, false, true}; Creating and Initializing Bool Arrays Method 1: Declaration with Size and Assignment ...
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 MoreUInt32.GetTypeCode() Method in C# with Examples
The UInt32.GetTypeCode() method in C# returns the TypeCode enumeration value for the UInt32 data type. This method is inherited from the IConvertible interface and is used to identify the underlying type of a value at runtime. The TypeCode enumeration provides a way to categorize the fundamental data types in .NET, making it useful for type checking and conversion operations. Syntax Following is the syntax for the UInt32.GetTypeCode() method − public TypeCode GetTypeCode(); Return Value This method returns TypeCode.UInt32, which represents the enumerated constant for the 32-bit unsigned integer type. Using GetTypeCode() ...
Read MoreWhat is the difference between a list and an array in C#?
An array stores a fixed-size sequential collection of elements of the same type, whereas a list is a generic collection that can dynamically resize during runtime. Understanding the differences between arrays and lists is crucial for choosing the right data structure for your C# applications. Syntax Following is the syntax for declaring and initializing an array − dataType[] arrayName = new dataType[size]; dataType[] arrayName = {value1, value2, value3}; Following is the syntax for declaring and initializing a list − List listName = new List(); List listName = new List {value1, value2, value3}; ...
Read MoreDefault operator in C#
The default operator in C# returns the default value for any data type. For value types, it returns zero or false, while for reference types, it returns null. The default expressions are evaluated at compile-time, making them efficient for initialization. Starting with C# 7.1, you can use the simplified default literal when the type can be inferred from the context. Syntax Following is the syntax for the traditional default operator − default(Type) Following is the syntax for the simplified default literal (C# 7.1+) − Type variable = default; Default ...
Read MoreImplicit conversion from Int16 to Decimal in C#
The short type in C# represents a 16-bit signed integer (Int16) that can store values from -32, 768 to 32, 767. C# allows implicit conversion from short to decimal because this conversion is always safe and will never result in data loss. An implicit conversion means the compiler automatically performs the type conversion without requiring an explicit cast operator. This is possible because decimal has a much larger range and precision than short. Syntax The syntax for implicit conversion from Int16 to Decimal is straightforward − short shortValue = value; decimal decimalValue = shortValue; ...
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 MoreDictionary.ContainsKey() Method in C#
The Dictionary.ContainsKey() method in C# checks whether the Dictionary contains the specified key. This method returns true if the key exists, otherwise false. Syntax public bool ContainsKey(TKey key); Parameters key − The key to locate in the dictionary. Cannot be null for reference types. Return Value Returns true if the dictionary contains an element with the specified key; otherwise, false. Using ContainsKey() to Check for Existing Keys This example demonstrates checking for a key that exists in the dictionary − using System; using System.Collections.Generic; public class Demo ...
Read More