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 91 of 2547
Decimal.ToDouble() Method in C#
The Decimal.ToDouble() method in C# is used to convert the value of the specified Decimal to the equivalent double-precision floating-point number. This conversion is useful when you need to perform operations that require double precision or when interfacing with APIs that expect double values. Syntax Following is the syntax − public static double ToDouble(decimal val); Parameters val − The decimal number to convert to a double-precision floating-point number. Return Value A double-precision floating-point number that is equivalent to the specified decimal value. Using Decimal.ToDouble() with Small Values Let us ...
Read MoreHow to copy a List collection to an array?
To copy a C# List collection to an array, you can use several methods. The most common approaches are the CopyTo() method, the ToArray() method, or creating an array with the List constructor. Syntax Following is the syntax for using CopyTo() method − list.CopyTo(array); list.CopyTo(array, arrayIndex); Following is the syntax for using ToArray() method − T[] array = list.ToArray(); Using CopyTo() Method The CopyTo() method copies all elements from the List to an existing array starting at the specified array index − using System; using System.Collections.Generic; ...
Read MoreHow to find the average of elements of an integer array in C#?
Finding the average of elements in an integer array is a common programming task in C#. The average is calculated by dividing the sum of all elements by the total number of elements in the array. Syntax The basic approach involves three steps − int[] array = {element1, element2, element3, ...}; int sum = 0; for (int i = 0; i < array.Length; i++) { sum += array[i]; } int average = sum / array.Length; Using For Loop to Calculate Average The traditional approach uses a for loop to ...
Read MoreDelete nth element from headnode using C#
Deleting the nth element from a linked list involves traversing to the target node and adjusting the links to bypass it. When deleting from the head position (n=1), we simply update the head reference. For other positions, we need to find the node before the target and redirect its Next pointer. Syntax Following is the basic structure for deleting the nth node − if (n == 1) { head = head.Next; return; } Node current = head; for (int i = 1; i < n - 1; ...
Read MoreUInt64.Equals Method in C# with Examples
The UInt64.Equals() method in C# returns a value indicating whether this instance is equal to a specified object or UInt64. This method provides a way to compare 64-bit unsigned integer values for equality, offering both generic object comparison and type-specific comparison overloads. Syntax Following is the syntax for both overloads of the UInt64.Equals() method − public override bool Equals(object obj); public bool Equals(ulong value); Parameters The UInt64.Equals() method accepts the following parameters − obj − An object to compare to this instance (first overload) value − A 64-bit unsigned integer to ...
Read MoreDecimal.ToInt16() Method in C#
The Decimal.ToInt16() method in C# is used to convert the value of the specified Decimal to the equivalent 16-bit signed integer (short). This method performs truncation, discarding any fractional part of the decimal number. Syntax Following is the syntax − public static short ToInt16(decimal val); Parameters val − The decimal number to convert. Return Value Returns a 16-bit signed integer (short) that is equivalent to the decimal value after truncation. The range of short is -32, 768 to 32, 767. Using Decimal.ToInt16() with Positive and Negative Values The method ...
Read MoreWhat are the differences between a list collection and an array in C#?
List collection is a generic class that can store any data type to create a dynamic collection. Arrays, on the other hand, store a fixed-size sequential collection of elements of the same type. Understanding the differences between these two collection types is crucial for choosing the right approach for your application. Syntax Following is the syntax for declaring and initializing a List − List listName = new List(); Following is the syntax for declaring and initializing an array − dataType[] arrayName = new dataType[size]; dataType[] arrayName = {value1, value2, value3}; ...
Read MoreReplace a string using StringBuilder
The StringBuilder class in C# provides an efficient way to modify strings without creating new string objects. The Replace() method allows you to replace all occurrences of a specified string or character with another string or character directly within the StringBuilder object. Syntax Following is the syntax for the Replace() method in StringBuilder − public StringBuilder Replace(string oldValue, string newValue) public StringBuilder Replace(char oldChar, char newChar) public StringBuilder Replace(string oldValue, string newValue, int startIndex, int count) Parameters oldValue/oldChar − The string or character to be replaced. newValue/newChar − The string or character ...
Read MoreC# Program to check whether the elements of a sequence satisfy a condition or not
The All() method in C# is used to check whether all elements in a sequence satisfy a specified condition. This method returns true only if every element meets the condition; if even one element fails the condition, it returns false. The All() method is part of LINQ (Language Integrated Query) and can be used with arrays, lists, and other enumerable collections. It uses lambda expressions to define the condition that each element must satisfy. Syntax Following is the syntax for using the All() method − bool result = collection.All(predicate); Where predicate is a ...
Read MoreDebug Class vs Debugger Class in C#
The Debug class and Debugger class in C# are both part of the System.Diagnostics namespace but serve different purposes. The Debug class provides methods for conditional debugging output, while the Debugger class enables communication and interaction with debuggers attached to your application. Debug Class The Debug class is a static class that provides conditional compilation methods for debugging. It outputs information only when the DEBUG symbol is defined during compilation − public static class Debug Properties of Debug Class Property Description AutoFlush Gets or sets a ...
Read More