- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 34488 Articles for Programming
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
773 Views
Create a thread first and start it −// new thread Thread thread = new Thread(c.display); thread.Start();Now display the thread and set a stop function to stop the working of the thread −public void display() { while (!flag) { Console.WriteLine("It's Working"); Thread.Sleep(2000); } } public void Stop() { flag = true; } }ExampleThe following is the complete code to learn how to kill a thread in C#.Live Demousing System; using System.Threading.Tasks; using System.Threading; class Demo { static void Main(string[] args){ MyClass c = new MyClass(); ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
397 Views
For the upper triangular matrix, set all the elements below the main diagonal to zero.Set the following condition −if (i = j) Console.Write(A[i, j] + "\t"); else Console.Write("0\t"); } } Console.ReadLine(); } }OutputEnter number of rows and columns of the matrix Enter elements: Upper Triangular Matrix
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
217 Views
For the lower triangular matrix, set all the elements above the main diagonal to zero.Set the following condition −if (i >= j) Console.Write(A[i, j] + "\t"); else Console.Write("0\t");ExampleYou can try to run the following code to display a lower triangular matrix.Live Demousing System; using System.Linq; class Demo { static void Main() { int m, n, i, j; Console.Write("Enter number of rows and columns of the matrix "); m = Convert.ToInt16(Console.ReadLine()); n = Convert.ToInt16(Console.ReadLine()); int[, ] A = new int[10, 10]; ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
247 Views
The sleep method of the thread is used to pause the thread for a specific period.If you want to set sleep for some seconds, then use it like the following code snippet −int sleepfor = 2000; Thread.Sleep(sleepfor);ExampleYou can try to run the following code to implement the sleep method of the thread.Live Demousing System; using System.Threading; namespace MyApplication { class ThreadCreationProgram { public static void CallToChildThread() { Console.WriteLine("Child thread starts"); int sleepfor = 2000; Console.WriteLine("Child Thread Paused for {0} seconds", sleepfor / 1000); ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
2K+ Views
Firstly find the hostname using the Dns.GetHostName() method in C# −String hostName = string.Empty; hostName = Dns.GetHostName(); Console.WriteLine("Hostname: "+hostName);Now, use the IPHostEntry.AddressList Property to get IP Address −IPHostEntry myIP = Dns.GetHostEntry(hostName); IPAddress[] address = myIP.AddressList;ExampleTry the following code to display IP address −using System; using System.Net; class Program { static void Main() { String hostName = string.Empty; hostName = Dns.GetHostName(); IPHostEntry myIP = Dns.GetHostEntry(hostName); IPAddress[] address = myIP.AddressList; for (int i = 0; i < address.Length; i++) { Console.WriteLine("IP Address {1} : ",address[i].ToString()); } Console.ReadLine(); } }
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
2K+ Views
Let’s say the following is the string −Hello WorldAfter reversing the string, the words should be visible like −olleH dlroWExampleUse the reverse() method and try the following code to reverse words in a string.Live Demousing System; using System.Linq; class Demo { static void Main() { // original string string str = "Hello World"; // reverse the string string res = string.Join(" ", str.Split(' ').Select(s => new String(s.Reverse().ToArray()))); Console.WriteLine(res); } }OutputolleH dlroW
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
3K+ Views
Firstly, set the original array −int[] arr = { 15, 16, 17, 18 }; // Original Array Console.WriteLine("Original Array= "); foreach (int i in arr) { Console.WriteLine(i); }Now, use the Array.reverse() method to reverse the array −Array.Reverse(arr);ExampleThe following is the complete code to reverse an array in C#Live Demousing System; class Demo { static void Main() { int[] arr = { 15, 16, 17, 18 }; // Original Array Console.WriteLine("Original Array= "); foreach (int i in arr) { Console.WriteLine(i); } // Reverse Array Array.Reverse(arr); Console.WriteLine("Reversed Array= "); foreach (int j in arr) { Console.WriteLine(j); } Console.ReadLine(); } }OutputOriginal Array= 15 16 17 18 Reversed Array= 18 17 16 15
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
11K+ Views
Our sample string is −myStr = "Tom";To reverse the string, firstly find the length of the string −// find string length int len; len = myStr.Length - 1;Now, use a while loop until the length is greater than 0 −while (len >= 0) { rev = rev + myStr[len]; len--; }ExampleYou can try to run the following code to reverse a string in C#.Live Demousing System; class Demo { static void Main() { string myStr, rev; myStr = "Tom"; rev =""; Console.WriteLine("String is {0}", myStr); ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
2K+ Views
We have a sample string with spaces −str ="Hello World !";Use the Replace() method in C# to replace all spaces in a string with ‘%20’ −str2 = str.Replace(" ", "%20");ExampleYou can try to run the following code to replace all spaces in a string with ‘%20’.Live Demousing System; class Demo { static void Main() { String str, str2; str ="Hello World !"; Console.WriteLine("String: "+str); str2 = str.Replace(" ", "%20"); Console.WriteLine("String (After replacing): "+str2); } }OutputString: Hello World ! String (After replacing): Hello%20World%20!
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
190 Views
Firstly, initialize three sorted arrays −int []one = {20, 35, 57, 70}; int []two = {9, 35, 57, 70, 92}; int []three = {25, 35, 55, 57, 67, 70};To find common elements in the three-sorted arrays, iterate through the arrays using a while loop and check the first array with a second and second array with the third −while (i < one.Length && j < two.Length && k < three.Length) { if (one[i] == two[j] && two[j] == three[k]) { Console.Write(one[i] + " "); i++;j++;k++; } else if (one[i] < two[j]) ... Read More