Samual Sam has Published 2310 Articles

C# program to find node in Linked List

Samual Sam

Samual Sam

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

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

C# program to convert decimal to Octal number

Samual Sam

Samual Sam

Updated on 19-Jun-2020 09:36:15

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

C# Program to Count the Number of 1's in the Entered Numbers

Samual Sam

Samual Sam

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

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

C# program to count total bits in a number

Samual Sam

Samual Sam

Updated on 19-Jun-2020 09:32:32

578 Views

Let us say the number we have is 12. We have declared and initialized a uint variable by assigning a decimal literal, uint val = 12;The binary representation of 12 is −1100The bits above is 4, therefore to find the total bits, use the Math.log() method −uint res = (uint)Math.Log(val ... Read More

C# Program to convert Digits to Words

Samual Sam

Samual Sam

Updated on 19-Jun-2020 09:29:32

4K+ Views

Firstly, declare the words from 0 to 9 −// words for every digits from 0 to 9 string[] digits_words = { "zero", "one", "two",    "three", "four", "five",    "six", "seven", "eight",    "nine" };The following are the digits to be converted to words −// number to be converted into ... Read More

C# Program to Convert Fahrenheit to Celsius

Samual Sam

Samual Sam

Updated on 19-Jun-2020 09:28:03

3K+ Views

Firstly, set the Fahrenheit temperature −double fahrenheit = 97; Console.WriteLine("Fahrenheit: " + fahrenheit);Now convert it into Celsius −celsius = (fahrenheit - 32) * 5 / 9;ExampleYou can try to run the following code to convert Fahrenheit to Celsius.Live Demousing System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Demo {   ... Read More

C# program to check if a string contains any special character

Samual Sam

Samual Sam

Updated on 19-Jun-2020 09:06:09

11K+ Views

To check if a string contains any special character, you need to use the following method −Char.IsLetterOrDigitUse it inside for loop and check or the string that has special characters.Let us say our string is −string str = "Amit$#%";Now convert the string into character array −str.ToCharArray();With that, use a for ... Read More

C# program to check password validity

Samual Sam

Samual Sam

Updated on 19-Jun-2020 09:05:00

894 Views

While creating a password, you may have seen the validation requirements on a website like a password should be strong and have −Min 8 char and max 14 charOne lower caseNo white spaceOne upper caseOne special charLet us see how to check the conditions one by one −Min 8 char ... Read More

C# program to convert a list of characters into a string

Samual Sam

Samual Sam

Updated on 19-Jun-2020 09:04:00

1K+ Views

Firstly, declare the character array and set the value of each character −char[] ch = new char[5]; ch[0] = 'H'; ch[1] = 'e'; ch[2] = 'l'; ch[3] = 'l'; ch[4] = 'o';Now, use the string class constructor and create a new string from the above array of characters −string ... Read More

C# program to count occurrences of a word in string

Samual Sam

Samual Sam

Updated on 19-Jun-2020 09:02:48

4K+ Views

Set the string first −string str = "Hello World! Hello!";Now check the string for the occurrences of a word “Hello’ and loop through −while ((a = str1.IndexOf(pattern, a)) != -1) {    a += pattern.Length;    count++; }ExampleYou can try to run the following code to count occurrences of a ... Read More

Advertisements