0
0
C Sharp (C#)programming~5 mins

Variable declaration and initialization in C Sharp (C#) - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a variable declaration in C#?
A variable declaration tells the computer to create a space in memory to store a value of a specific type, like int or string.
Click to reveal answer
beginner
What does variable initialization mean?
Initialization means giving a variable its first value when you create it, for example: int age = 25; sets the variable age to 25 right away.
Click to reveal answer
beginner
How do you declare and initialize a string variable named name with the value "Alice"?
You write: string name = "Alice"; This creates a variable called name that holds the text "Alice".
Click to reveal answer
beginner
Can you declare a variable without initializing it? Give an example.
Yes, you can declare a variable without giving it a value immediately. For example: int number; declares the variable but does not set its value yet.
Click to reveal answer
intermediate
What happens if you try to use a variable before initializing it in C#?
C# will give an error because variables must have a value before you use them. The compiler wants to make sure you don’t use empty or unknown values.
Click to reveal answer
Which of the following is a correct variable declaration and initialization in C#?
Acount int = 10;
Bint count = 10;
Cint = 10 count;
Dint count;
What type of value can a variable of type bool hold?
ATrue or False
BAny number
CText strings
DDecimal numbers
What is the result of this code?<br>int x;<br>Console.WriteLine(x);
ACompilation error
BPrints a random number
CPrints null
DPrints 0
Which of the following can be used to declare a variable in C#?
AAll of the above
Blet
Cint
Dvar
How do you declare a variable without initializing it?
Aint number = 0;
Bnumber int;
Cint = number;
Dint number;
Explain in your own words what variable declaration and initialization mean in C#.
Think about how you tell the computer to remember something and give it a value.
You got /4 concepts.
    Describe what happens if you try to use a variable before initializing it in C#.
    What does the computer say if you try to use empty memory?
    You got /3 concepts.