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 82 of 2547
Decimal.ToUInt16() Method in C#
The Decimal.ToUInt16() method in C# is used to convert the value of the specified Decimal to the equivalent 16-bit unsigned integer (ushort). This method performs a narrowing conversion, truncating any fractional part. Syntax Following is the syntax − public static ushort ToUInt16(decimal val); Parameters val − The decimal number to convert to a 16-bit unsigned integer. Return Value Returns a ushort value that represents the converted decimal. The fractional part is truncated (not rounded). How It Works The method truncates the decimal value to the ...
Read MoreHow to create 7-Tuple or Septuple in C#?
The Tuple class represents a 7-tuple, also known as a septuple. A tuple is a data structure that contains a fixed number of elements in a specific sequence, allowing you to group related values together. 7-tuples are commonly used for − Easier access to a data set with seven related values. Easier manipulation of a data set. To represent a single set of data with seven components. To return multiple values from a method. To pass multiple values to a method. Syntax Following is the syntax for creating a 7-tuple in C# − ...
Read MoreWhat is method overloading in C#?
Method overloading in C# allows you to define multiple methods with the same name but different parameters. This enables you to create methods that perform similar operations but accept different types or numbers of arguments. Method overloading can be achieved by changing the number of parameters, the data types of parameters, or the order of parameters. The compiler determines which method to call based on the arguments passed at runtime. Syntax Following is the syntax for method overloading − public returnType MethodName(type1 param1) { } public returnType MethodName(type1 param1, type2 param2) { } public returnType ...
Read MoreHow to append a second list to an existing list in C#?
Use the AddRange() method to append a second list to an existing list in C#. The AddRange() method adds all elements from one collection to the end of another list, effectively combining two lists into one. Syntax Following is the syntax for using AddRange() method − list1.AddRange(list2); Parameters collection − The collection whose elements should be added to the end of the List. The collection itself cannot be null, but it can contain elements that are null. Using AddRange() Method The AddRange() method modifies the original list by adding ...
Read MoreCheck if a File is hidden in C#
To check if a file is hidden in C#, use the FileAttributes enumeration which contains various file attribute members like Compressed, Directory, Hidden, and others. The FileAttributes.Hidden flag indicates whether a file has the hidden attribute set. You can retrieve file attributes using File.GetAttributes() and then check for the Hidden flag using bitwise operations. Syntax Following is the syntax for getting file attributes − FileAttributes attributes = File.GetAttributes(filePath); Following is the syntax for checking if a file is hidden − bool isHidden = (attributes & FileAttributes.Hidden) == FileAttributes.Hidden; Using ...
Read MoreDateTime.SpecifyKind() Method in C#
The DateTime.SpecifyKind() method in C# is used to create a new DateTime object that has the same number of ticks as the specified DateTime but is designated as either local time, Coordinated Universal Time (UTC), or neither, as indicated by the specified DateTimeKind value. This method is particularly useful when you have a DateTime value but need to explicitly specify its time zone context without changing the actual time value. The original DateTime remains unchanged − a new instance is returned with the specified Kind property. Syntax Following is the syntax for the DateTime.SpecifyKind() method − ...
Read MoreDateTimeOffset.GetHashCode() Method in C#
The DateTimeOffset.GetHashCode() method in C# returns a hash code for the current DateTimeOffset object. This method is inherited from the Object class and provides a 32-bit signed integer that represents the unique identifier for the DateTimeOffset instance, which is useful for hash-based collections like Dictionary and HashSet. Syntax Following is the syntax for the GetHashCode() method − public override int GetHashCode(); Return Value This method returns a 32-bit signed integer hash code that represents the current DateTimeOffset object. Two DateTimeOffset objects that are equal will have the same hash code, but objects with ...
Read MoreReverse a Stack using C#
A stack is a Last-In-First-Out (LIFO) data structure in C#. To reverse a stack, we can use another stack and leverage the LIFO property by popping elements from the original stack and pushing them into a new stack. The System.Collections.Stack class provides Push() and Pop() methods that make stack reversal straightforward. Syntax Following is the basic syntax for creating and reversing a stack − Stack originalStack = new Stack(); Stack reversedStack = new Stack(); while (originalStack.Count != 0) { reversedStack.Push(originalStack.Pop()); } How Stack Reversal Works The reversal process ...
Read MoreLong Time ("T") Format Specifier in C#
The Long Time ("T") format specifier in C# is a standard date and time format specifier that displays the time portion of a DateTime value in a long format. This format is culture-sensitive and displays the full time representation including hours, minutes, seconds, and AM/PM designator where applicable. The "T" format specifier is defined by the DateTimeFormatInfo.LongTimePattern property and typically follows the pattern HH:mm:ss for 24-hour format or includes AM/PM for 12-hour format, depending on the culture. Syntax Following is the syntax for using the Long Time format specifier − dateTime.ToString("T") dateTime.ToString("T", CultureInfo.CreateSpecificCulture("culture-name")) ...
Read MoreCheck if a File exists in C#
The File.Exists() method in C# is used to check whether a file exists at a specified path. This method returns true if the file exists, and false if it does not. It is part of the System.IO namespace and provides a simple way to verify file existence before performing file operations. Syntax Following is the syntax for the File.Exists() method − public static bool Exists(string path) Parameters path − The file path to check. Can be a relative path (current directory) or absolute path (full path including drive). Return Value ...
Read More