Programming Articles

Page 856 of 2547

C# Program to create a Simple Thread

Samual Sam
Samual Sam
Updated on 17-Mar-2026 645 Views

In C#, a thread represents a separate execution path that can run concurrently with other threads. The System.Threading.Thread class allows you to create and manage threads in your application. To create a simple thread, you define a method that contains the code you want to execute, then create a Thread object using a ThreadStart delegate that points to your method. Syntax Following is the syntax for creating a thread − Thread threadName = new Thread(new ThreadStart(methodName)); threadName.Start(); You can also use the simplified syntax − Thread threadName = new Thread(methodName); threadName.Start(); ...

Read More

C# Enum Equals Method

George John
George John
Updated on 17-Mar-2026 800 Views

The Equals() method in C# is used to compare enum values for equality. It returns true if both enum values have the same underlying value, and false otherwise. Syntax Following is the syntax for using the Equals() method with enums − enumValue1.Equals(enumValue2) Parameters enumValue2 − The enum value to compare with the current enum value Return Value The method returns a bool value − true if both enum values are equal false if the enum values are different ...

Read More

C# Program to Create a Thread Pool

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 745 Views

A thread pool in C# is a collection of pre-created threads that can be reused to execute multiple tasks efficiently. Instead of creating new threads for each task, the thread pool manages a pool of worker threads, reducing the overhead of thread creation and destruction. The ThreadPool class provides methods to queue work items for execution by available threads in the pool. This approach is particularly useful for short-running tasks that don't require dedicated threads. Syntax Following is the syntax for queueing a method for execution in the thread pool − ThreadPool.QueueUserWorkItem(new WaitCallback(methodName)); ...

Read More

What is overloading in C#?

Samual Sam
Samual Sam
Updated on 17-Mar-2026 3K+ Views

C# provides two techniques to implement static polymorphism − Function overloading Operator overloading Function Overloading Function overloading in C# allows multiple methods with the same name but different parameters within the same class. The compiler determines which method to call based on the number, types, and order of arguments passed. Syntax Following is the syntax for function overloading − public returnType MethodName(parameter1) { } public returnType MethodName(parameter1, parameter2) { } public returnType MethodName(differentType parameter) { } Method Overloading Resolution Add(int, ...

Read More

What is a sealed class in C#?

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 900 Views

A sealed class in C# is a class that cannot be inherited by other classes. When you declare a class as sealed, it prevents any other class from deriving from it. The sealed keyword can also be applied to methods to prevent them from being overridden in further derived classes. Sealed classes are useful when you want to restrict inheritance for security, performance, or design reasons. Common examples include the string class and many value types in .NET Framework. Syntax Following is the syntax for declaring a sealed class − public sealed class ClassName { ...

Read More

File Objects in C#

George John
George John
Updated on 17-Mar-2026 1K+ Views

The FileStream class in C# is used to create, read, write, and manipulate files. It provides low-level access to file operations and is part of the System.IO namespace. FileStream works with bytes, making it suitable for both text and binary files. Syntax Following is the syntax for creating a FileStream object − FileStream objectName = new FileStream(fileName, FileMode, FileAccess, FileShare); A simplified syntax for common scenarios − FileStream objectName = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite); Parameters Parameter Description Common Values fileName Path and ...

Read More

Convert.ToUInt32 Method in C#

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 358 Views

The Convert.ToUInt32 method in C# converts a specified value to a 32-bit unsigned integer (uint). This method can convert various data types including strings, integers, floating-point numbers, and other numeric types to an unsigned 32-bit integer. The uint data type can hold values from 0 to 4, 294, 967, 295, making it suitable for scenarios where you need positive integers only with a larger range than regular int. Syntax Following are the common overloads of the Convert.ToUInt32 method − Convert.ToUInt32(string value) Convert.ToUInt32(int value) Convert.ToUInt32(double value) Convert.ToUInt32(object value) Parameters value − The ...

Read More

C# Program to find whether the Number is Divisible by 2

Samual Sam
Samual Sam
Updated on 17-Mar-2026 8K+ Views

A number is divisible by 2 if the remainder is 0 when the number is divided by 2. This is checked using the modulo operator (%) in C#, which returns the remainder of a division operation. Numbers divisible by 2 are called even numbers, while numbers not divisible by 2 are called odd numbers. Divisibility by 2 Check Even Numbers num % 2 == 0 Examples: 2, 4, 6, 8, 10 Odd Numbers num % 2 ...

Read More

What does Array.Length property of array class do in C#?

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 168 Views

The Array.Length property in C# is used to get the total number of elements in an array. This property returns an integer value representing the array's size, which is essential for array manipulation and iteration. Syntax Following is the syntax for using the Array.Length property − int length = arrayName.Length; Return Value The Length property returns an int value representing the total number of elements in the array. Using Array.Length with Array.CreateInstance The following example demonstrates how to use Array.Length with dynamically created arrays − using System; class ...

Read More

How to truncate a file in C#?

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 1K+ Views

To truncate a file in C#, use the FileStream.SetLength method. This method allows you to change the size of a file by either reducing it (truncating) or expanding it to a specified length. Syntax Following is the syntax for the SetLength method − public override void SetLength(long value); Parameters value − A long representing the desired length of the stream in bytes. How It Works The behavior of SetLength depends on whether the new value is smaller or larger than the current file size − ...

Read More
Showing 8551–8560 of 25,466 articles
« Prev 1 854 855 856 857 858 2547 Next »
Advertisements