Csharp Articles

Page 86 of 196

C# program to find IP Address of the client

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

To find the IP address of the client machine in C#, we use the DNS (Domain Name System) class from the System.Net namespace. This involves getting the hostname first and then resolving it to obtain the associated IP addresses. Syntax Following is the syntax to get the hostname − string hostName = Dns.GetHostName(); Following is the syntax to get IP addresses from hostname − IPHostEntry hostEntry = Dns.GetHostEntry(hostName); IPAddress[] addresses = hostEntry.AddressList; How It Works The process involves two main steps: Dns.GetHostName() retrieves the hostname of the ...

Read More

C# Program to Illustrate Lower Triangular Matrix

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

A lower triangular matrix is a square matrix where all elements above the main diagonal are zero. In other words, for any element at position (i, j), if j > i, then the element is zero. The main diagonal consists of elements where the row index equals the column index (i = j). Below the diagonal, elements can have any non-zero values. Syntax The condition to check if an element should be displayed or set to zero − if (i >= j) // Display the actual element else ...

Read More

C# program to Illustrate Upper Triangular Matrix

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

An upper triangular matrix is a square matrix where all elements below the main diagonal are zero. In an upper triangular matrix, elements are preserved only on or above the main diagonal (where row index ≤ column index). Upper Triangular Matrix 1 2 3 4 0 5 6 7 0 0 8 9 0 0 0 10 Zero below diagonal Non-zero on/above diagonal Logic To display an upper triangular matrix, we use the condition i

Read More

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

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

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

C# program to find the maximum of three numbers

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

Finding the maximum of three numbers is a fundamental programming problem that demonstrates conditional logic and comparison operations. This can be achieved using nested if-else statements to compare the numbers systematically. Logic The algorithm compares numbers in pairs − First, compare num1 with num2 If num1 is greater, compare num1 with num3 If num2 is greater than num1, compare num2 with num3 The winner of each comparison is the maximum Finding Maximum Logic Flow num1 num2 ...

Read More

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# Program to Create a Thread Pool

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 744 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

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
Showing 851–860 of 1,951 articles
« Prev 1 84 85 86 87 88 196 Next »
Advertisements