- 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 34494 Articles for Programming
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
597 Views
To display a line, Console.Write() is used in C#.Console displays the result on the console. I have first set a string.string str = "Tom Hanks is an actor";Now displaying the above line.Console.WriteLine(str);The following is the complete code −Example Live Demousing System; namespace Program { public class Demo { public static void Main(String[] args) { string str = "Tom Hanks is an actor"; Console.WriteLine("Displaying a line below"); Console.WriteLine(str); Console.ReadLine(); } } }OutputDisplaying a line below Tom Hanks is an actor
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
242 Views
With C#, you can easily display the following diamond shape.$ $$$ $$$$$ $$$$$$$ $$$$$$$$$ $$$$$$$ $$$$$ $$$ $To display a diamond shape, you need to focus on the following points −Number of rows Dollar sign to be displayed Empty spacesConsidering the above you can easily create the diamond shape as shown in the below code −Example Live Demousing System; namespace Program { public class Demo { public static void Main(String[] args) { int i, j, r, d, e; // rows = 5 r = 5; // display dollar sign d = 1; // empty space e = r - 1; for (i = 1; i < r * 2; i++) { // display empty space for (j = 1; j
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
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!
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
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
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
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!
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
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!
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
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
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
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