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 809 of 2547
Assertions in C#
Assertions in C# are debugging tools used to check assumptions in your code during development. They have two main arguments − a boolean expression that should evaluate to true, and an optional message to display if the assertion fails. Assertions are particularly useful in large and complex programs to quickly identify logic errors that may arise when code is modified. They help catch bugs early in the development process. Syntax Following is the syntax for using Debug.Assert() − Debug.Assert(condition); Debug.Assert(condition, "Error message"); Debug.Assert(condition, "Error message", "Detailed message"); Key Rules Assertions ...
Read MoreHow to declare variables in C#?
Each variable in C# has a specific type, which determines the size and layout of the variable's memory, the range of values that can be stored within that memory, and the set of operations that can be applied to the variable. Variables must be declared before they can be used. Declaration tells the compiler what type of data the variable will hold and reserves memory accordingly. Syntax Following is the basic syntax for declaring variables in C# − ; You can also declare multiple variables of the same type in a single ...
Read MoreWays to print escape characters in C#
The following are the escape characters in C# and the display column suggests how to use and print them in C# − Escape Character Description Pattern Display \a Matches a bell character, \u0007. \a "\u0007" in "Warning!" + '\u0007' \b In a character class, matches a backspace, \u0008. [\b]{3, } "\b\b\b\b" in "\b\b\b\b" \t Matches a tab, \u0009. (\w+)\t "Name\t", "Addr\t" in "Name\tAddr\t" \r Matches a carriage return, \u000D. (\r is not equivalent to the newline character, .) \r(\w+) "\rHello" in "\r\HelloWorld." \v Matches ...
Read MoreNumbers in C#
Numbers in C# are represented by various data types, with int being the most commonly used for whole numbers. The int type represents a 32-bit signed integer that can store values from -2, 147, 483, 648 to 2, 147, 483, 647. Basic Integer Operations C# supports standard mathematical operations on integers using arithmetic operators. Here's how to perform basic addition − using System; class Program { static void Main() { int x = 20; int y = 30; ...
Read MoreSemaphore in C#
A Semaphore in C# is a synchronization primitive that controls access to a pool of resources by allowing a specified number of threads to enter a critical section simultaneously. It maintains a count of available permits and blocks threads when the limit is reached. The System.Threading.Semaphore class provides all the methods and properties needed to implement semaphore functionality in multithreaded applications. Syntax The basic syntax for creating a semaphore − Semaphore semaphore = new Semaphore(initialCount, maximumCount); To acquire and release the semaphore − semaphore.WaitOne(); // Acquire the semaphore ...
Read MoreC# Program to Subtract Two TimeSpan
In C#, the TimeSpan structure represents a time interval and provides methods to perform arithmetic operations. To subtract one TimeSpan from another, you can use the Subtract() method or the subtraction operator (-). Syntax Following is the syntax for subtracting TimeSpan objects using the Subtract() method − TimeSpan result = timeSpan1.Subtract(timeSpan2); Following is the syntax using the subtraction operator − TimeSpan result = timeSpan1 - timeSpan2; Using Subtract() Method The Subtract() method returns a new TimeSpan that represents the difference between two TimeSpan values − using System; ...
Read MoreLong Date ("D") Format Specifier in C#
The "D" format specifier in C# represents the long date format pattern. It displays dates in a culture-specific long format, showing the full day name, month name, day, and year without time information. The format string is defined by the culture's DateTimeFormatInfo.LongDatePattern property and varies based on the specified culture. Syntax Following is the syntax for using the "D" format specifier − DateTime.ToString("D") DateTime.ToString("D", CultureInfo) The default custom format string for English (US) culture is − dddd, dd MMMM yyyy Using "D" Format with Default Culture Example ...
Read MoreMath.IEEERemainder() Method in C#
The Math.IEEERemainder() method in C# returns the remainder resulting from the division of a specified number by another specified number. Unlike the modulus operator (%), this method follows the IEEE 754 standard for floating-point arithmetic, which can produce different results in certain cases. The IEEE remainder is calculated as dividend - (divisor * Math.Round(dividend / divisor)), where the division result is rounded to the nearest even integer when exactly halfway between two integers. Syntax public static double IEEERemainder(double dividend, double divisor); Parameters dividend − A double-precision floating-point number (the number to be ...
Read MoreAre arrays zero indexed in C#?
Yes, arrays are zero-indexed in C#. This means the first element of an array is stored at index 0, the second element at index 1, and so on. The relationship between array length and indexing follows a consistent pattern. Array Length vs Index Range If the array is empty, it has zero elements and length 0. If the array has one element at index 0, then it has length 1. If the array has two elements at indexes 0 and 1, then it has length 2. If the array has ...
Read MoreWay to read input from console in C#
The Console.ReadLine() method is the primary way to read input from the console in C#. This method reads a complete line of text from the console and returns it as a string. Since all console input is received as text, you need to convert it to the appropriate data type when working with numbers or other non-string values. Syntax Following is the syntax for reading console input − string input = Console.ReadLine(); For converting string input to other data types − int number = Convert.ToInt32(input); ...
Read More