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 102 of 2547
How 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 MoreHow to use ReadKey() method of Console class in C#?
The Console.ReadKey() method in C# reads the next character or function key pressed by the user. This method is commonly used to pause program execution until the user presses a key, which is particularly useful when running console applications from Visual Studio to prevent the console window from closing immediately. Syntax The Console.ReadKey() method has two overloads − public static ConsoleKeyInfo ReadKey(); public static ConsoleKeyInfo ReadKey(bool intercept); Parameters intercept (optional): A boolean value that determines whether to display the pressed key in the console. If true, the key is not displayed; if ...
Read MoreDefault value of StringBuilder in C#
The default operator in C# returns the default value for any data type. For reference types like StringBuilder, the default value is null. This is useful when you need to initialize a StringBuilder variable without creating an instance immediately. Syntax Following is the syntax for using the default operator with StringBuilder − StringBuilder variable = default(StringBuilder); In C# 7.1 and later, you can also use the simplified syntax − StringBuilder variable = default; Using default(StringBuilder) Example using System; using System.Text; public class Demo { ...
Read MoreImplicit conversion from Char to Decimal in C#
In C#, implicit conversion from char to decimal happens automatically when you assign a character value to a decimal variable. The character is converted to its corresponding ASCII or Unicode numeric value, which is then stored as a decimal number. Syntax Following is the syntax for implicit conversion from char to decimal − char c = 'character'; decimal dec = c; // implicit conversion How It Works When you assign a char to a decimal, C# automatically converts the character to its numeric ASCII/Unicode value. For example, the character 'A' has an ...
Read More