George John has Published 1080 Articles

Formatted output in C#

George John

George John

Updated on 22-Jun-2020 09:26:01

2K+ Views

To format output in C#, let us see examples to format date and double type.Set formatted output for Double type.Example Live Demousing System; class Demo {    public static void Main(String[] args) {       Console.WriteLine("Three decimal places...");       Console.WriteLine(String.Format("{0:0.000}", 987.383));       Console.WriteLine(String.Format("{0:0.000}", 987.38));   ... Read More

How to print multiple blank lines in C#?

George John

George John

Updated on 22-Jun-2020 09:14:20

841 Views

To display multiple blank lines, we will take a while loop.Here, we are printing 10 blank lines using Console.WriteLine();while (a < 10) {    Console.WriteLine(" ");    a++; }The following is the complete code to display multiple blank lines −Exampleusing System; namespace Program {    public class Demo {   ... Read More

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

George John

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

Keywords in C#

George John

George John

Updated on 22-Jun-2020 08:58:35

721 Views

Keywords are reserved words predefined to the C# compiler. These keywords cannot be used as identifiers. However, if you want to use these keywords as identifiers, you may prefix the keyword with the @ character.The following are the two types of keywords in C#.Reserved KeywordsabstractasbaseBoolbreakbytecasecatchcharcheckedClassconstcontinuedecimaldefaultdelegatedoDoubleelseenumeventexplicitexternfalseFinallyfixedfloatforforeachgotoifImplicitinin (generic modifier)intinterfaceinternalisLocklongnamespacenewnullobjectoperatorOutout (generic modifier)overrideparamsprivateprotectedpublicReadonlyrefreturnsbytesealedshortsizeofstackallocstaticstringstructswitchthisthrowTruetrytypeofuintulonguncheckedunsafeUshortusingvirtualvoidvolatilewhileContextual Keywordsaddaliasascendingdescendingdynamicfromgetglobalgroupintojoinletorderbypartial ... Read More

How to print duplicate characters in a String using C#?

George John

George John

Updated on 22-Jun-2020 08:53:54

5K+ Views

Set maximum value for char.static int maxCHARS = 256;Now display the duplicate characters in the string.String s = "Welcometomywebsite!"; int []cal = new int[maxCHARS]; calculate(s, cal); for (int i = 0; i < maxCHARS; i++) if(cal[i] > 1) {    Console.WriteLine("Character "+(char)i);    Console.WriteLine("Occurrence = " + cal[i] ... Read More

How to perform Matrix Addition using C#?

George John

George John

Updated on 22-Jun-2020 08:40:51

1K+ Views

To perform matrix addition, take two matrices. Enter the rows and columns of matrix one and matrix two. Remember, both the matrix should be a square matrix to add them.Now add elements to both the matrices. Declare a new array and add both the arrays in it.arr3[i, j] = arr1[i, ... Read More

How to call Math Operations using Delegates in C#?

George John

George John

Updated on 22-Jun-2020 08:24:21

377 Views

To understand how to call Math Operations using Delegates in C#, let us see an example wherein we will divide a number.We have a class and a function in it −public class Demo {    public static double DivideFunc(double value) {       return value / 5;    } ... Read More

What is the difference between Read(), ReadKey() and ReadLine() methods in C#?

George John

George John

Updated on 22-Jun-2020 07:44:43

2K+ Views

Read()The Read() reads the next characters from the standard input stream. If a key is pressed on the console, then it would close.int az = Console.Read() Console.WriteLine(z);ReadKey()It reads only a single charactare from the standard input stream.ReadLine()Reads the next line of characters from the standard input stream.Example Live Demousing System; class ... Read More

What is the difference between Read() and ReadLine() methods in C#?

George John

George John

Updated on 22-Jun-2020 07:40:15

857 Views

Read()The Read() reads the next characters from the standard input stream. If a key is pressed on the console, then it would close.int a = Console.Read() Console.WriteLine(a);ReadLine()It reads the next line of characters from the standard input stream.Example Live Demousing System; class Program {    static void Main() {   ... Read More

CSS position: static;

George John

George John

Updated on 22-Jun-2020 07:34:21

269 Views

The position: static; property sets the position of an element static, which is the default.ExampleThe top, bottom, left, and right properties does not affect the the static positioned elements. You can try to run the following code to implement the CSS position: static; propertyLive Demo           ... Read More

Advertisements