Karthikeya Boyini has Published 2383 Articles

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

karthikeya Boyini

karthikeya Boyini

Updated on 19-Jun-2020 11:33:45

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 ... Read More

C# program to reverse an array

karthikeya Boyini

karthikeya Boyini

Updated on 19-Jun-2020 11:30:41

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 ... Read More

C# program to find IP Address of the client

karthikeya Boyini

karthikeya Boyini

Updated on 19-Jun-2020 11:28:29

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 {   ... Read More

C# Program to Illustrate Lower Triangular Matrix

karthikeya Boyini

karthikeya Boyini

Updated on 19-Jun-2020 11:26:45

215 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 { ... Read More

What happens when we apply NOT NULL constraint, with ALTER TABLE statement, to a column contains NULL values?

karthikeya Boyini

karthikeya Boyini

Updated on 19-Jun-2020 11:26:11

172 Views

In this case, MySQL will return an error message regarding data truncated for the column. Following is an example of demonstrating it −ExampleSuppose we have a table ‘test2’ which contains a NULL value in column ‘ID’ at 2nd row. Now, if we will try to declare the column ID to ... Read More

C# Program to display name of Current Thread

karthikeya Boyini

karthikeya Boyini

Updated on 19-Jun-2020 11:17:38

165 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 ... Read More

C# program to display factors of entered number

karthikeya Boyini

karthikeya Boyini

Updated on 19-Jun-2020 11:15:47

940 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

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

karthikeya Boyini

karthikeya Boyini

Updated on 19-Jun-2020 10:52:36

913 Views

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

C# Program to count number of Vowels and Consonants in a string

karthikeya Boyini

karthikeya Boyini

Updated on 19-Jun-2020 09:35:14

582 Views

You need to check for both the vowels and consonants, but do not forget to check for both the uppercase as well lowercase.For counting vowels, check for “aeiou” characters separately i.e.if (myStr[i] == 'a' || myStr[i] == 'e' || myStr[i] == 'i' || myStr[i] == 'o' || myStr[i] == 'u' ... Read More

C# program to count the occurrences of each character

karthikeya Boyini

karthikeya Boyini

Updated on 19-Jun-2020 09:33:20

22K+ Views

Firstly, set the string −string str = "Website"; Console.WriteLine("String: "+str);Check for every character in the string and increment a variable that would count the number of occurrences of that character −for (int j = 0; j < str.Length; j++) {    if (str[0] == str[j]) {       cal++; ... Read More

Advertisements