Programming Articles

Page 102 of 2547

How to copy files into a directory in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 4K+ Views

To copy files in C#, the File.Copy method is the primary approach. This method allows you to copy individual files from one location to another, with options to control whether existing files should be overwritten. Syntax The File.Copy method has two overloads − File.Copy(string sourceFileName, string destFileName) File.Copy(string sourceFileName, string destFileName, bool overwrite) Parameters sourceFileName − The file to copy. destFileName − The name of the destination file. This cannot be a directory. overwrite − true if the destination file should be overwritten if it already exists; otherwise, false. ...

Read More

Stack.Equals() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 371 Views

The Stack.Equals() method in C# is used to check whether a Stack class object is equal to another object or not. This method performs reference equality, not content equality, meaning it returns true only if both variables reference the same Stack object in memory. Syntax Following is the syntax for the Stack.Equals() method − public virtual bool Equals(object obj); Parameters obj − The object to compare with the current Stack instance. Return Value Returns true if the specified object is the same instance as the current Stack; otherwise, false. ...

Read More

Difference Between Delegates and Events in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 2K+ Views

In C#, both delegates and events are used for callback mechanisms, but they serve different purposes and have distinct characteristics. Understanding their differences is crucial for proper C# programming and design patterns. Delegates A delegate is a type that represents references to methods with a specific signature. It acts as a function pointer that can hold references to one or more methods during runtime. Syntax public delegate returnType DelegateName(parameters); Example using System; public delegate void MyDelegate(string message); public class DelegateExample { public static void Method1(string ...

Read More

Explain and contrast value types and reference types in C#

Akshay Khot
Akshay Khot
Updated on 17-Mar-2026 420 Views

In C#, all types can be divided into two main categories − value types and reference types. Understanding the difference between these types is crucial for memory management and avoiding common programming errors. Value Types Variables of value types directly contain their data. Each variable has its own copy of the data, stored on the stack. When you assign one value type variable to another, the entire value is copied. Value types in C# include − All numeric types: int, float, double, decimal, byte, etc. char and bool types struct ...

Read More

Stack.GetEnumerator() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 156 Views

The Stack.GetEnumerator() method in C# returns an IEnumerator that allows you to iterate through the elements of a Stack collection. This method provides a way to manually control the iteration process using the enumerator pattern, as an alternative to using foreach loops. Syntax Following is the syntax for the GetEnumerator() method − public virtual System.Collections.IEnumerator GetEnumerator(); Return Value The method returns an IEnumerator object that can be used to iterate through the Stack elements. The enumerator starts before the first element and advances using MoveNext(), with the current element accessed via the Current ...

Read More

Get an enumerator that iterates through Collection in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 157 Views

To get an enumerator that iterates through a Collection in C#, you use the GetEnumerator() method. An enumerator provides a way to iterate through collection elements one by one using MoveNext() and Current properties. The Collection class is part of the System.Collections.ObjectModel namespace and provides a generic collection that can be customized by inheritance. Syntax Following is the syntax for getting and using an enumerator − var enumerator = collection.GetEnumerator(); while (enumerator.MoveNext()) { // Access current element using enumerator.Current } How It Works GetEnumerator() returns an IEnumerator ...

Read More

Check the HybridDictionary for a specific key in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 166 Views

The HybridDictionary class in C# provides the Contains() method to check whether a specific key exists in the collection. This method returns true if the key is found, otherwise false. HybridDictionary is part of the System.Collections.Specialized namespace and automatically switches between a ListDictionary and Hashtable based on the number of entries for optimal performance. Syntax Following is the syntax for checking if a key exists in HybridDictionary − public virtual bool Contains(object key) Parameters The Contains() method accepts the following parameter − key − The key to locate in the HybridDictionary. ...

Read More

C# Program to Show the Use of Exists Property

Sabid Ansari
Sabid Ansari
Updated on 17-Mar-2026 2K+ Views

The Exists method in C# is a useful method that checks whether any element in a List matches a given condition. This method takes a predicate as an argument and returns a bool value indicating whether any element exists in the list that satisfies the specified condition. Syntax Following is the syntax for the Exists method − public bool Exists(Predicate match) Parameters match − A Predicate delegate that defines the conditions of the elements to search for. Return Value Returns true if at least one element matches the specified ...

Read More

Provide a brief overview of the C# and .NET ecosystem

Akshay Khot
Akshay Khot
Updated on 17-Mar-2026 747 Views

C# is an object-oriented, type-safe and general-purpose programming language, which focuses on making the programmers productive. It tries to achieve this productivity through expressiveness, simplicity and a focus on performance. It works on different platforms such as Windows, Mac, and Linux. The .NET ecosystem provides the foundation for C# development, offering a comprehensive runtime environment, extensive libraries, and tools for building various types of applications from desktop to web and mobile solutions. Type-Safety C# is a statically typed language. That means the types are verified when you compile a program. This eliminates a large set of errors ...

Read More

TimeSpan.FromHours() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 1K+ Views

The TimeSpan.FromHours() method in C# is used to create a TimeSpan object that represents a specified number of hours. This static method is accurate to the nearest millisecond and provides a convenient way to create time spans based on hour values. Syntax Following is the syntax for the TimeSpan.FromHours() method − public static TimeSpan FromHours(double value); Parameters value − A double that represents the number of hours. The value can be positive or negative and is accurate to the nearest millisecond. Return Value This method returns a ...

Read More
Showing 1011–1020 of 25,467 articles
« Prev 1 100 101 102 103 104 2547 Next »
Advertisements