Welcome to Practice C# Console! There are over 20 beginner C#exercises just waiting to be solved. The best way we learn anything is by practice and exercise questions. We have started this section for those (beginner) who are familiar with C#.
The answers are at the end of the post
C# Exercise Questions
1-) Which one ise valid variable?
1 2 3 4 5 6 7 8 9 | #name user name userName 1.User |
2-) Define a variable that name is a “number” and assign a value of 100
3-) Write the types of the following variables
1 2 3 4 5 6 7 | a=3.15; b=true; c="Coders"; d=20; e='a'; |
4-) Which of the following is correct for entering the newline after typed string in the console screen
1 2 3 4 5 6 | Console.println("Hello"); Console.Write("Hello"); Console.WriteLine("Hello"); Console.PrintLine("Hello"); |
4-) What is the output of the following code
1 2 3 4 5 6 | int s1=2; int s2=0; Console.Write(s1); Console.Write(s2); |
6-) Fill the following blanks for read from the console application
1 2 3 4 | string variable; variable=______________________; |
7-) What kind of code do you enter for converting string to integer
1 2 3 4 5 | int=number; string str="120"; number=_______________________; |
8 -) How do you comment out a large block of code in C#
1 2 3 4 5 6 | <!-- comment--> !# comment# // comment// /* comment*/ |
9-) What is the type of the “a” variable in the following code?
1 2 3 | var a="sample"; |
10-) Which of the following is correct defination for a constant
1 2 3 4 5 6 | const double PI = 3.14159; double P I=3.14159; const PI=3.14159; final dobule PI=3.14159; |
11-) Fill in the missing operator to calculate power of x.
1 2 3 4 5 | int x=5; int power=x _ x; Console.Write("Power="+power); |
12-) What is the output of the following code
1 2 3 4 5 | int a=23; int b=5; Console.WriteLine(a/b); |
13-) Which operator is used to calculate the remainder
1 2 3 4 5 6 | + / > % |
14-) Fill the following blank for calculate b=b/5 by short syntax
1 2 3 | b _= 5; |
15-) What is the output of the following code
1 2 3 4 | int a=5; Console.WriteLine(a++); |
16-) What is the output of the following code
1 2 3 4 | int a=5; Console.WriteLine(--a); |
17-) Which operator is used to check equality
1 2 3 4 5 6 | = == === != |
18-) if “a” is higher than “b”, write “a is higher” else write “a is not higher”
1 2 3 4 5 6 7 8 9 10 11 12 | int a=20; int b=7; __(a __ b) { Console.WriteLine("a is higher"); } __ { Console.WriteLine("a is not higher"); } |
19-) What is the output of the following code
1 2 3 4 5 6 7 8 9 10 | int a=8; int b=7; b++; if(a > b) b++; else a--; Console.Write(a+b); |
20-) Fill the following blanks for write three times “hello world” on the console screen
1 2 3 4 5 6 7 8 | int a=0; ____(a __ 3) { Console.WriteLine("Merhaba Dünya"); a__; } |
C# Exercise Questions Answers
- userName
- int number;
number=100; - a:double, b:bool, c:string, d:int, e:char
- Console.WriteLine(“Hello”);
- 20
- Console.ReadLine();
- Convert.ToInt32(str);
- /* comment*/
- String
- const double PI=3.14159;
- *
- 4
- %
- /
- 5
- 4
- ==
- if, >, else
- 15
- while, <=, ++
The exercises consists of mainly college level , in fact, most exercises are directly from the book. My goal was to solve these exercises as a student would.