Csharp Articles

Page 121 of 196

C# program to Reverse words in a string

Samual Sam
Samual Sam
Updated on 19-Jun-2020 3K+ 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

Read More

C# program to find IP Address of the client

karthikeya Boyini
karthikeya Boyini
Updated on 19-Jun-2020 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();    } }

Read More

C# Program to Illustrate Lower Triangular Matrix

karthikeya Boyini
karthikeya Boyini
Updated on 19-Jun-2020 304 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

C# Program to display name of Current Thread

karthikeya Boyini
karthikeya Boyini
Updated on 19-Jun-2020 289 Views

To display the name of the current thread in C#, use the Name property.Firstly, use the currentThread property to display information about a thread −Thread thread = Thread.CurrentThread;Now use the thread.Name property to display name of the thread −thread.NameExampleLet us see the complete code show current thread’s name in C#.Live Demousing System; using System.Threading; namespace Demo {    class MyClass {       static void Main(string[] args) {          Thread thread = Thread.CurrentThread;          thread.Name = "My Thread";          Console.WriteLine("Thread Name = {0}", thread.Name);          Console.ReadKey();       }    } }OutputThread Name = My Thread

Read More

C# Program to display priority of Thread

Samual Sam
Samual Sam
Updated on 19-Jun-2020 444 Views

To show the priority of the thread in C#, use the Priority property.Firstly, use the currentThread property to display information about a thread −Thread thread = Thread.CurrentThread;Now use the thread.Priority property to display the priority of the thread −thread.PriorityExampleLet us see the complete code to show the thread’s priority in C#.Live Demousing System; using System.Threading; namespace Demo {    class MyClass {       static void Main(string[] args) {          Thread thread = Thread.CurrentThread;          thread.Name = "My Thread";          Console.WriteLine("Thread Priority = {0}", thread.Priority);          Console.ReadKey();       }    } }OutputThread Priority = Normal

Read More

C# program to display factors of entered number

karthikeya Boyini
karthikeya Boyini
Updated on 19-Jun-2020 1K+ Views

Firstly, enter the number for which you want the factors −Console.WriteLine("Enter the Number:"); n = int.Parse(Console.ReadLine());After that, loop through to find the factors −for (i = 1; i

Read More

C# program to count upper and lower case characters in a given string

karthikeya Boyini
karthikeya Boyini
Updated on 19-Jun-2020 1K+ Views

To count uppercase characters in a string, check the following condition −myStr[i]>='A' &amp;&amp; myStr[i]='a' &amp;&amp; myStr[i]

Read More

C# program to find node in Linked List

Samual Sam
Samual Sam
Updated on 19-Jun-2020 623 Views

Firstly, create a new linked list −LinkedList myList = new LinkedList();Now add some elements in the linked list −// Add 6 elements in the linked list myList.AddLast("P"); myList.AddLast("Q"); myList.AddLast("R"); myList.AddLast("S"); myList.AddLast("T"); myList.AddLast("U");Let’s now find a node and add a new node after that −LinkedListNode node = myList.Find("R"); myList.AddAfter(node, "ADDED");ExampleYou can try to run the following code to find a node in the linked list.Live Demousing System; using System.Collections.Generic; class Program {    static void Main() {       LinkedList myList = new LinkedList();       // Add 6 elements in the linked list       myList.AddLast("P");   ...

Read More

C# program to convert decimal to Octal number

Samual Sam
Samual Sam
Updated on 19-Jun-2020 814 Views

Set the decimal number −int decVal = 40;Now take a variable and set the decVal in it. Find the remainder with 8 since octal has base-8 number system and evaluate it in a loop like the following code snippet.while (quot != 0) {    octalVal[i++] = quot % 8;    quot = quot / 8; }ExampleYou can try to run the following code to convert decimal to octal number.Live Demousing System; class Demo {    public static void Main() {       int decVal, quot, i = 1, j;       int[] octalVal = new int[80];     ...

Read More

C# Program to Count the Number of 1&#039;s in the Entered Numbers

Samual Sam
Samual Sam
Updated on 19-Jun-2020 666 Views

I have added the numbers using an array −int[] num = new int[] {1, 25, 1, 55, 1};Now loop through and find for 1, if 1 is there, 6 then increment the variable that counts the occurrence −foreach(int j in num) {    if (j == 1) {       cal++;    } }ExampleThe following is the code to count the number of 1’s in the entered number.Live Demousing System; public class Demo {    public static void Main() {       int cal = 0;       int[] num = new int[] {1, 25, 1, 55, ...

Read More
Showing 1201–1210 of 1,951 articles
« Prev 1 119 120 121 122 123 196 Next »
Advertisements