Found 2628 Articles for Csharp

How to print a BinaryTriangle using C#?

Arjun Thakur
Updated on 22-Jun-2020 09:17:39

377 Views

Binary triangle is formed with 0s and 1s. To create one, you need to work around a nestes for loop and display 0s and 1s till the row entered.for (int i = 1; i

How to print a blank line in C#?

karthikeya Boyini
Updated on 22-Jun-2020 09:18:05

2K+ Views

To display a line in C#, use the Console.WriteLine().Under that set a blank line −Console.WriteLine(" ");The following is the code that displays a blank line −Example Live Demousing System; namespace Program {    public class Demo {       public static void Main(String[] args) {          Console.WriteLine(" ");          Console.WriteLine("Displayed a blank line above!");          Console.ReadLine();       }    } }OutputDisplayed a blank line above!

How to find date difference in C#?

Samual Sam
Updated on 22-Jun-2020 09:18:41

75 Views

To find the difference between two dates in C#, you need to first set two dates to be compared using the DateTime object. We will use the DateTime class in C#.Date 1DateTime date1 = new DateTime(2018, 09, 15); Console.WriteLine("Date 1 : {0}", date1);Date 2DateTime date2 = new DateTime(2018, 09, 28); Console.WriteLine("Date 2 : {0}", date2);Now let us compare both the dates in C#. The following is an example to compare dates in C#.Example Live Demousing System; namespace Program {    class Demo {       static int Main() {          DateTime date1 = new DateTime(2018, 09, 15); ... Read More

How to find and display the Multiplication Table in C#?

Chandu yadav
Updated on 22-Jun-2020 09:00:08

725 Views

To display multiplication table, you need to set the numbers and format the output property. Let’s say you want to find the table of 4 from 1 to 10. For that, set a while loop first till 10.while (a

How to find a substring from a string in C#?

karthikeya Boyini
Updated on 22-Jun-2020 09:03:24

202 Views

Set the stringstring s = "Tom Cruise";Now let’s say you need to find the substring “Tom”, then use the Contains() method.if (s.Contains("Tom") == true) {    Console.WriteLine("Substring found!"); }The following is the code to learn how to find a substring from a string −Example Live Demousing System; public class Demo {    public static void Main() {       string s = "Tom Cruise";       if (s.Contains("Tom") == true) {          Console.WriteLine("Substring found!");       } else {          Console.WriteLine("Substring not found!");       }    } }OutputSubstring found!

How to find a replace a word in a string in C#?

George John
Updated on 22-Jun-2020 09:04:03

4K+ Views

Firstly, set the string to be replaced.string str = "Demo text!";Now use the replace() method to replace the above string.string res = str.Replace("Demo ", "New ");The following is the complete code to replace a word in a string.Example Live Demousing System; public class Demo {    public static void Main() {       string str = "Demo text!";       Console.WriteLine(str);       string res = str.Replace("Demo ", "New ");       Console.WriteLine("After replacing...");       Console.WriteLine(res);    } }OutputDemo text! After replacing... New text!

How to find a number in a string in C#?

Ankith Reddy
Updated on 22-Jun-2020 09:05:10

269 Views

To find a number in a string, use Regular Expressions.We have set the Regex pattern to get number from a string.Regex r = new Regex(@"\d+");Now, use Match class in C# to set the string.Match m = r.Match("Welcome! We are open 365 days in a year!");Use the Success property now to display the result if number is found in the string as shown in the following complete code −Example Live Demousing System; using System.Text.RegularExpressions; class Demo {    static void Main() {       Regex r = new Regex(@"\d+");       Match m = r.Match("Welcome! We are open ... Read More

How to find a number using Pythagoras Theorem using C#?

Samual Sam
Updated on 22-Jun-2020 09:04:37

338 Views

Firstly, set the first two numbers −double val1, val2; val1 = 10; val2 = 5;Now use the Math.Sqrt function to use Pythagoras Theorem.res = Math.Sqrt(val1 * val1 + val2 * val2);Example Live Demousing System; public class Program {    public static void Main(string[] args) {       double val1, val2, res;       val1 = 10;       val2 = 5;       res = Math.Sqrt(val1 * val1 + val2 * val2);       Console.WriteLine("Result = {0}", res);       Console.ReadLine();    } }OutputResult = 11.1803398874989

How to remove an empty string from a list of empty strings in C#?

karthikeya Boyini
Updated on 22-Jun-2020 09:06:28

878 Views

Firstly, set a list with empty string as elements.List myList = new List() {    " ",    " ",    " " };Now let us remove one empty element using index.myList.RemoveAt(0);Example Live Demousing System; using System.Collections.Generic; using System.Linq; class Program {    static void Main() {       List myList = new List() {          " ",          " ",          " "       };       Console.Write("Initial list with empty strings...");       foreach (string list in myList) {         ... Read More

How to remove an item from an ArrayList in C#?

Arjun Thakur
Updated on 27-Mar-2020 10:51:33

274 Views

Firstly, set a a new ArrayList and add elements to it.ArrayList arr = new ArrayList(); arr.Add( "Jones" ); arr.Add( "Tom" ); arr.Add( "Henry" );Now let’s remove the item “Tom”. For that, use the Remove() method.arr.Remove("Tom");The following is the complete example to remove an element from ArrayList −Example Live Demousing System; using System.Collections; class Demo {    static void Main(){       ArrayList arr = new ArrayList();       arr.Add( "Jones" );       arr.Add( "Tom" );       arr.Add( "Henry" );       Console.WriteLine("Initial ArrayList...");       foreach(string str in arr) {   ... Read More

Advertisements