Server Side Programming Articles

Page 761 of 2109

C# program to replace all spaces in a string with '%20'

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

When working with strings in C#, you may need to replace spaces with '%20' for URL encoding or other formatting purposes. The Replace() method provides a simple way to substitute all occurrences of a character or substring with another value. Syntax Following is the syntax for using the Replace() method − string newString = originalString.Replace(oldValue, newValue); Parameters oldValue − The string or character to be replaced newValue − The string or character to replace with Return Value The method returns a new string with all occurrences of the specified ...

Read More

C# program to Reverse words in a string

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

In C#, reversing words in a string means reversing each individual word while keeping the words in their original positions. For example, "Hello World" becomes "olleH dlroW" where each word is reversed but the word order remains the same. Syntax Using LINQ with Split(), Select(), and Reverse() methods − string result = string.Join(" ", str.Split(' ').Select(word => new string(word.Reverse().ToArray()))); Using a traditional loop approach − string[] words = str.Split(' '); for (int i = 0; i < words.Length; i++) { words[i] = ReverseWord(words[i]); } string result = string.Join(" ...

Read More

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 329 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 613 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 649 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
Showing 7601–7610 of 21,090 articles
« Prev 1 759 760 761 762 763 2109 Next »
Advertisements