C# Flashcards
What framework does C# run on?
The .NET Framework.
What method is used to print to console?
Console.WriteLine(“message”);
How do you use writeline placeholders?
Console.WriteLine(“My name is {0} and I am {1} years old”, x, y);
What method is used to get user input?
Console.ReadLine();
How do you convert value types?
Convert.ToXXX
int32, bool, int64
How do you implicitely type a variable?
var (instead of int or bool or whatever)
What is the difference between ++i and i++?
++i increments then proceeds with the expression, i++ does the opposite.
How do you use switch cases?
switch (num){ case 1: //code break; case 2: //code break; default: //code }
What does the continue keyword do?
Breaks the current iteration only
How do you use conditional operator?
msg = Exp1 ? Exp2 : Exp 3;
How do you set a default value for a method parameter?
void method(int x, int y=2);
How can you place your arguments in any order when calling a method?
By calling the parameter variables in the arguments
Ex: method(x: 5, y: 8);
How can you use references in methods and change variable values from a method?
with the ref keyword
void method(ref int y);
method(ref x)
What is similar to a ref, but does not require you to initialize a variable?
out
What is overloading?
Defining methods with the same names but with different parameters.