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.Cos() Method in C#
The Math.Cos() method in C# returns the cosine of a specified angle. The angle must be provided in radians, not degrees. This method is part of the System.Math class and is commonly used in mathematical calculations, graphics programming, and trigonometric operations. Syntax Following is the syntax for the Math.Cos() method − public static double Cos(double val); Parameters val − A double value representing the angle in radians whose cosine is to be calculated. Return Value The method returns a double value representing the cosine of the specified ...
Read MoreMathF.Abs() Method in C# with Examples
The MathF.Abs() method in C# is used to return the absolute value of a float number. The absolute value represents the non-negative value of a number without regard to its sign. For example, the absolute value of both -5.5f and 5.5f is 5.5f. This method is part of the System namespace and is specifically designed for float operations, providing better performance than the generic Math.Abs() method when working with single-precision floating-point numbers. Syntax Following is the syntax for the MathF.Abs() method − public static float Abs(float val); Parameters val − A ...
Read MoreAssertions 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 More