Reverse a Stack using C#

Ankith Reddy
Updated on 17-Mar-2026 07:04:35

4K+ Views

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 More

Long Time ("T") Format Specifier in C#

karthikeya Boyini
Updated on 17-Mar-2026 07:04:35

512 Views

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 More

Check if a File exists in C#

Samual Sam
Updated on 17-Mar-2026 07:04:35

10K+ Views

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

DateTimeOffset.CompareTo() Method in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:35

159 Views

The DateTimeOffset.CompareTo() method in C# compares the current DateTimeOffset object to a specified DateTimeOffset object and indicates whether the current object is earlier than, the same as, or later than the second DateTimeOffset object. It returns an integer value based on the comparison result − < 0 − If this object is earlier than the specified value 0 − If this object is the same as the specified value > 0 − If this object is later than the specified value Syntax Following is the syntax − public int CompareTo(DateTimeOffset value); ... Read More

DateTimeOffset.ToFileTime() Method in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:35

146 Views

The DateTimeOffset.ToFileTime() method in C# is used to convert the value of the current DateTimeOffset object to a Windows file time. The method returns an Int64 value representing the current DateTimeOffset object, expressed as a Windows file time. A Windows file time is a 64-bit value that represents the number of 100-nanosecond intervals that have elapsed since 12:00 midnight, January 1, 1601 A.D. (UTC). This format is commonly used by Windows file systems to store file timestamps. Syntax Following is the syntax − public long ToFileTime(); Return Value The method returns a ... Read More

What are the main parts of a C# program?

Samual Sam
Updated on 17-Mar-2026 07:04:35

2K+ Views

The main parts of a C# program include − Namespace declaration A class Class methods Class attributes A Main method Statements and Expressions Comments Understanding these components is essential for writing effective C# programs. Each part serves a specific purpose in organizing and executing your code. Basic C# Program Structure The following example demonstrates a simple C# program with all the essential parts − using System; namespace Demo { class Program { // Class attribute (field) ... Read More

An array of streams in C#

karthikeya Boyini
Updated on 17-Mar-2026 07:04:35

849 Views

An array of streams in C# refers to using arrays or collections along with stream objects like StreamWriter and StreamReader to perform file I/O operations. This approach is commonly used when you need to write multiple data items from an array to a file or read file content into an array structure. Syntax Following is the syntax for writing array data to a file using StreamWriter − using (StreamWriter writer = new StreamWriter("filename.txt")) { foreach (dataType item in arrayName) { writer.WriteLine(item); ... Read More

Sorting a String in C#

Samual Sam
Updated on 17-Mar-2026 07:04:35

7K+ Views

Sorting a string array in C# is accomplished using the Array.Sort() method, which arranges elements in alphabetical order. This method modifies the original array and uses lexicographic comparison by default. Syntax Following is the basic syntax for sorting a string array − Array.Sort(arrayName); For custom sorting, you can use an overloaded version − Array.Sort(arrayName, StringComparer.OrdinalIgnoreCase); Using Array.Sort() for String Arrays The Array.Sort() method sorts string arrays in ascending alphabetical order. Here's how it works − using System; public class Program { public static ... Read More

Full Date Short Time ("f") Format Specifier in C#

Ankith Reddy
Updated on 17-Mar-2026 07:04:35

251 Views

The Full Date Short Time ("f") format specifier in C# represents a combination of the long date ("D") and short time ("t") patterns. It displays the complete date information along with hours and minutes in a readable format. This format specifier is culture-sensitive and will display dates according to the specified culture's formatting conventions. Syntax Following is the syntax for using the "f" format specifier − DateTime.ToString("f") DateTime.ToString("f", CultureInfo.CreateSpecificCulture("culture-code")) Using "f" Format Specifier with Default Culture Example using System; class Demo { static void Main() { ... Read More

What is the IsFixedSize property of Hashtable class in C#?

karthikeya Boyini
Updated on 17-Mar-2026 07:04:35

152 Views

The IsFixedSize property of the Hashtable class in C# returns a bool value indicating whether the Hashtable has a fixed size. When this property returns false, you can add or remove elements. When it returns true, the size is fixed and you cannot add or remove elements. For a regular Hashtable created using the default constructor, IsFixedSize always returns false, meaning it can grow dynamically as you add elements. Syntax Following is the syntax to check if a Hashtable has a fixed size − bool isFixed = hashtable.IsFixedSize; Return Value The IsFixedSize ... Read More

Advertisements