Professional Documents
Culture Documents
Final Programming Hamed Abu Alnsr
Final Programming Hamed Abu Alnsr
Page |1
Programming Language 1
Each method, in turn, may contain a set of ore or more statements and each statement represent a
command to execute
using System; means that we can use classes from the System namespace.
Write( )vs WriteLine()
*Single line vs multiple line comments
variables are containers for storing data values
Constant variables
It's not allowed to define constant variable without assigning value to it
For numeric values, the + character works as a mathematical operator
To define identifier;
It is recommended to use descriptive names in order to create understandable and maintainable
code
Names can contain only letters. digits and the underscore ()
Names must begin with a letter or an underscore.
Names cannot contain a white space.
Names are case sensitive (e.g. my Var and my var are different).
Reserved words (e.g. int or double) can not be used as names.
Page |2
Programming Language 1
Some important points which you should be fully aware of in chapte5 & 6
Use if to specify a block of code to be executed. if a specified condition is true
Use else lo specify a block of code to be executed, if the same condition if false
Use else if to specify a new condition to test, if the first condition is false
Use switch to specify many alternative blocks of code to be executed
It is always legal in C4 to nest if statements. which means you can use one if or if-else statement
inside another if or else statement(s).
nested if is able to reduce the number of comparisons
the switch statement to select one of many code blocks to be executed.
The switch expression is evaluated once
The value of the expression is compared with the values of each case
If there is a match, the associated block of code is executed
A break can save a lot of execution time because it "ignores" the execution of all the rest of the code
in the switch block.
The default keyword is optional and specifies some code to run if there is no case match;
1- To write single line comment in c# you must start the line by...
a.@ b./* C. // d.*/
2- To write multiple line comment in c# you must start the line by...
a. @ b./* C.// d.*/
3- To write multiple line comment in e# you must ends the comment lines by...
a.@ b./* C.// d.*/
5- Which of the following is the correct ways to set a value 3.14 in a variable pi such that it
cannot be modified?
A. float pi =3.14 F; B. #define pi 3.14 F c. const float pi =3.14 F; D. const float pi; pi =3.14 F;
a. @ b. * c. ; d.{
Page |3
Programming Language 1
Note
Page |4
Programming Language 1
int x=3;
int y=10;
if (x < y)
Console.writeLine (x<y)
else
Console.WriteLine(x>y);
a. x<y b. x>y c. true d. false
a. i'm in if i'm in main b. i'm in else i'm in main c. i'm in main d.error
If (5<10)
{
Console.WriteLine("welcome");
}
Else
{
break;
}
a. welcome b. error c. nothing d. break;
Page |5
Programming Language 1
A. 5650 B. 61 c. 44 d. 11
A. 5650 B.61 c. 29 d. 44
A.20 b. 20.6
Page |6
Programming Language 1
Bool x = false;
//Console.WriteLine(Convert.Tolnt32(x));
a. 0 b.1 c. True d. This code is true but not have any printing statement
33. To take an integer input from user what of the following is correct
Int num=5;
Page |7
Programming Language 1
a. True b. False
a. True b. False
a. True b. false
a. True b. false
a. * b. / c. + d. !
Page |8
Programming Language 1
int x=0;
if (++x==0)
{
Console.WriteLine(x);
x
}
else
{
Console.WriteLine ("welcome");
}
A. X B.1 C.0 D. welcome
46.The ------keyword that specifies what do you do when the condition of if is not true?
A. true B. false
51. The data type that able to store this value ‘A’
Page |9
Programming Language 1
a. True b. False
a. True b. False
a. True b. False
booly=x!;
bool x=false ;
Console.WriteLine(y) ;
a. True b. False
bool x=false;
bool y=!x
Console.WriteLine(y);
a. True b. false
A B C
a. true b. false
P a g e | 10
Programming Language 1
int x=100;
x=+1 ;
Console.WriteLine(x)
int input=Console.ReadLine();
this code will leads an error message [ Cannot implicitly convert type 'string'to 'int]
The solution to avoid this problem, is to use the backslash escape character (1) to turns special characters into string
characters
string x="true" ;
Console.WriteLine(y);|
a. Error b. True C. 0
65. What will do if Note: If you enter wrong input ( e.g text in a numerical input)
correct format
P a g e | 11