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
Csharp Articles
Page 153 of 196
Represent Int32 as a Hexadecimal String in C#
To represent Int32 as a hexadecimal string in C#, you can use several methods. The most common approaches are using Convert.ToString() with base 16, or using the ToString() method with hexadecimal format specifiers. Int32 represents a 32-bit signed integer that can hold values from -2, 147, 483, 648 to 2, 147, 483, 647. Converting these values to hexadecimal format is useful for debugging, display purposes, and when working with low-level operations. Using Convert.ToString() with Base 16 The Convert.ToString() method accepts a base parameter. Setting it to 16 converts the integer to its hexadecimal representation − ...
Read MoreC# Program to find the longest string from an array of strings using Lambda Expression
Lambda expressions in C# provide a concise way to write anonymous functions. When working with arrays of strings, you can use lambda expressions with LINQ methods like Aggregate() to perform operations such as finding the longest string. In this example, we'll demonstrate how to find the longest string from an array using the Aggregate() method with a lambda expression. Syntax The Aggregate() method with lambda expression follows this syntax − collection.Aggregate(seed, (accumulator, next) => condition ? next : accumulator, result => transformation) Where − seed − Initial value for comparison accumulator ...
Read MoreC# Program to remove a node at the beginning of a Linked List
To remove a node at the beginning of a LinkedList in C#, use the RemoveFirst() method. This method removes the first node from the LinkedList and automatically adjusts the internal structure. Syntax Following is the syntax for the RemoveFirst() method − linkedList.RemoveFirst(); This method removes the first node and does not return any value. If the LinkedList is empty, it throws an InvalidOperationException. How It Works When you call RemoveFirst(), the LinkedList performs the following operations − RemoveFirst() Operation ...
Read MoreImplicit conversion from Int32 to Decimal in C#
The int type represents a 32-bit signed integer (Int32) in C#. C# allows implicit conversion from int to decimal because this conversion is always safe and does not result in data loss. The decimal type has a much larger range and precision than int. Syntax The syntax for implicit conversion from Int32 to decimal is straightforward − int intValue = 123; decimal decimalValue = intValue; // implicit conversion No explicit casting is required because the conversion is safe and automatic. How Implicit Conversion Works When you assign an int value to ...
Read MoreC# Program to remove a node at the end of the Linked List
In C#, you can remove the last node from a LinkedList using the RemoveLast() method. This method removes and returns the last node in the linked list, making it an efficient way to delete the tail element. Syntax Following is the syntax for removing the last node from a LinkedList − linkedList.RemoveLast(); The RemoveLast() method removes the last node and has no return value. If the list is empty, it throws an InvalidOperationException. How It Works The LinkedList class maintains references to both the first and last nodes. When RemoveLast() is called, ...
Read MoreC# Program to rename a file
In C#, you can rename a file using the File.Move() method from the System.IO namespace. This method moves a file from one location to another, and when the source and destination paths are in the same directory with different filenames, it effectively renames the file. Syntax Following is the syntax for renaming a file using File.Move() − File.Move(string sourceFileName, string destFileName); Parameters sourceFileName − The current path and name of the file to rename. destFileName − The new path and name for the file. Using File.Move() to Rename Files ...
Read MoreImplicit conversion from 8-bit signed integer (SByte) to Decimal in C#
SByte represents an 8-bit signed integer with values ranging from -128 to 127. C# allows implicit conversion from sbyte to decimal because this conversion is always safe and does not result in data loss. Syntax Following is the syntax for implicit conversion from sbyte to decimal − sbyte sbyteValue = value; decimal decimalValue = sbyteValue; // implicit conversion How It Works The conversion happens automatically without requiring explicit casting because decimal can represent all possible sbyte values without precision loss. The 8-bit signed integer is widened to fit into the 128-bit decimal ...
Read MoreShort Date ("d") Format Specifier
The "d" format specifier in C# represents the short date pattern for formatting DateTime values. This standard format specifier produces a compact date representation without time information, making it ideal for displaying dates in a concise format. The format string is defined by the culture's DateTimeFormatInfo.ShortDatePattern property, which varies based on the current culture settings. Syntax Following is the syntax for using the "d" format specifier − DateTime.ToString("d") DateTime.ToString("d", CultureInfo) The default custom format string for invariant culture is − MM/dd/yyyy Using "d" Format Specifier with Different Cultures ...
Read MoreC# Enum ToString() Method
The ToString() method in C# enums converts the enum value to its equivalent string representation. This method provides different formatting options to display enum values as either their names or underlying numeric values. Syntax Following are the common syntax forms for enum ToString() method − enumValue.ToString() // Returns name enumValue.ToString("G") // Returns name (General format) enumValue.ToString("d") // Returns decimal value enumValue.ToString("D") // Returns decimal value Parameters ...
Read MoreC# Enum Parse Method
The Enum.Parse method in C# converts the string representation of an enum constant name or its numeric value into an equivalent enumerated object. This method is essential when you need to convert string data back into strongly-typed enum values. Syntax Following are the main syntax forms for Enum.Parse − // Basic syntax public static object Parse(Type enumType, string value) // With ignore case option public static object Parse(Type enumType, string value, bool ignoreCase) Parameters enumType − The type of the enumeration to parse to value − A string containing the name ...
Read More