Programming Articles

Page 854 of 2547

C# Program to Kill a Thread

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 1K+ Views

In C#, a thread can be gracefully stopped using a flag-based approach rather than forcibly terminating it. This method allows the thread to complete its current work and exit cleanly by checking a boolean flag in its loop condition. The recommended approach involves setting a boolean flag that the thread periodically checks. When you want to stop the thread, you set the flag to true, causing the thread's loop to exit naturally. Syntax Following is the syntax for creating and controlling a thread with a stop flag − Thread thread = new Thread(methodName); thread.Start(); ...

Read More

How do I determine the size of my array in C#

seetha
seetha
Updated on 17-Mar-2026 260 Views

In C#, determining the size of an array is accomplished using the Length property. This property returns the total number of elements in the array as an int value. Syntax Following is the syntax for getting array length − arrayName.Length Parameters The Length property does not take any parameters and returns an integer representing the number of elements. Return Value Returns an int value indicating the total number of elements in the array. Using Length Property for Single-Dimensional Arrays For single-dimensional arrays, the Length property provides a direct count ...

Read More

Type.GetFields() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 370 Views

The Type.GetFields() method in C# is used to retrieve the fields of the current Type using reflection. This method returns an array of FieldInfo objects representing the fields that match the specified binding criteria. Fields are data members of a class that store values. The GetFields() method allows you to examine both public and non-public fields at runtime, making it useful for inspection, debugging, and dynamic programming scenarios. Syntax Following is the syntax for the parameterless overload − public System.Reflection.FieldInfo[] GetFields(); Following is the syntax for the overload with binding flags − ...

Read More

C# Program to pass Parameter to a Thread

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

To work with threads in C#, you need to add the System.Threading namespace. Passing parameters to threads allows you to send data from the main thread to worker threads, enabling more flexible and dynamic thread operations. Syntax Following is the syntax for creating a thread and passing a parameter − Thread thread = new Thread(ThreadMethod); thread.Start(parameter); The thread method must accept an object parameter − static void ThreadMethod(object parameter) { // cast parameter to appropriate type } Using Thread.Start() with a Parameter The Thread.Start(object) method accepts ...

Read More

Represent Int32 as a String in C#

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

The Int32 type in C# represents a 32-bit signed integer. To convert an Int32 value to its string representation, you can use the ToString() method. This method converts the numeric value into a readable string format. Syntax Following is the syntax for converting an Int32 to string using ToString() − int number = value; string result = number.ToString(); You can also use format specifiers with ToString() − string result = number.ToString("format"); Using ToString() Method Basic Conversion Example The simplest way to convert an Int32 to string is using ...

Read More

What is aggregation in C#?

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 531 Views

Aggregation in C# represents a has-a relationship between objects where one class contains or uses another class. In aggregation, the contained object can exist independently of the container object, making it a weak association. For example, an Employee has an Address, and a Department has multiple Employees. The key characteristic of aggregation is that when the container object is destroyed, the contained objects continue to exist independently. Syntax Following is the syntax for implementing aggregation in C# − public class ContainerClass { private ContainedClass containedObject; ...

Read More

Mathematical Functions in C#

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 2K+ Views

The System.Math class in C# provides methods and properties to perform mathematical operations, trigonometric calculations, logarithmic functions, and other common mathematical computations. All methods in the Math class are static, meaning you can call them directly without creating an instance. Common Mathematical Methods The following table shows some of the most commonly used methods in the Math class − Method Description Abs() Returns the absolute value of a number (works with decimal, double, int, etc.) Ceiling() Returns the smallest integer greater than or equal to the specified number ...

Read More

How to List all Substrings in a given String using C#?

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

A substring is any contiguous sequence of characters within a string. In C#, you can generate all possible substrings of a given string using the Substring() method with nested loops to iterate through different starting positions and lengths. Syntax The Substring() method extracts a portion of a string − string.Substring(startIndex, length) To generate all substrings, use nested loops − for (int length = 1; length

Read More

C# Console.WindowWidth Property

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

The Console.WindowWidth property gets or sets the width of the console window measured in columns. This property is useful for creating console applications that need to adapt their output formatting based on the current window dimensions. Syntax Following is the syntax to get the console window width − int width = Console.WindowWidth; Following is the syntax to set the console window width − Console.WindowWidth = value; Return Value The property returns an int representing the width of the console window in columns. When setting the property, the value must ...

Read More

C# Program to perform all Basic Arithmetic Operations

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

Basic arithmetic operators in C# allow you to perform mathematical calculations such as addition, subtraction, multiplication, division, and modulus operations. These operators work with numeric data types and form the foundation of mathematical computations in C#. Arithmetic Operators Operator Description + Adds two operands - Subtracts the second operand from the first * Multiplies both operands / Divides the numerator by denominator % Modulus operator returns the remainder after division ++ Increment operator increases integer value by one -- ...

Read More
Showing 8531–8540 of 25,466 articles
« Prev 1 852 853 854 855 856 2547 Next »
Advertisements