C# Basics / File I/O / Console App Flashcards
How would you display a line of text in the console?
Console.Write() - to continue on same line Console.WriteLine() - to start new line after displayed
What is string interpolation and how is it used?
String interpolation enables you to insert values in string literals to create formatted strings.

How would you read a sting literally or verbatim?
@”C:Windows\System32”
What is composite formatting of parameters?
{Index [, alignment][:formatString]
Console.WriteLine(“{0,-20} {1,5}\n”, “Name”, “Hours”);
// The example displays the following output:
// Name Hours
What is a list?
A list is similar to an array but provides additional functionality, such as dynamic resizing.
Define: Index
Index is a number starting from 0 that identifies a corresponding item in the list of objects.
Define: Alignment
Alignmet is a signed integer indicating the preferred formatted field width
Define: Format string
Format String is a format string that is appropriate for the type of object being formatted
What datatypes does C# read from the keyboard?
ONLY STRINGS, unline java, so the need for parsing is often used
How would you parse a readline to an integer?

What is the other way to convert a sting into an integer?
int myAge = Convert.ToInt32(input)
What is the naming convention for methods inside of a class in C#?
Pascal not camel case!
eg. SetName
How would you manually create a property to get and set the instance variable?

What would a Class diagram look like with a property?

How would you manually add validation to a property set method?
Private decimal balance: // instance variabl

How would you create an auto-implemented property?
public string Name { get; set; }
What is the format specifier for currency and how is it used?
Format Specifier :C

What are the main format specifiers?

What are the default values for the simple data types in C#?
Types char, byte, sbyte, short, ushort, int, uint, long, ulong, float, double, and decimal are all given the value 0 by default.
Type bool are given a value of false by default.
Reference-type instance variables are of type null by default.
What datatype do you use for monetary amounts?
decimal
What are the conversion types of datatypes?

What is an optional paramater and how is it used?
Methods can have optional parameters that allow the calling method to vary the number of arguments to pass. An optional parameter specifies a default value that’s assigned to the parameter if the optional argument is omitted. You can create methods with one or more optional parameters. All optional parameters must be placed to the right of the method’s non-optional parameters.
eg. static int Power(int baseValue, int exponentValue = 2);
What are names parameters and how are they used?
C# provides a feature called named parameters, which enable you to call methods that receive optional parameters by providing only the optional arguments you wish to specify.
Explicitly specify the parameter’s name and value—separated by a colon (:)—in the argument list of the method call.
For example:
// sets the time to 12:00:22
t.SetTime( hour: 12, second: 22 );
The compiler assigns parameter hour the argument 12 and parameter second the argument 22. The parameter minute is not specified, so the compiler assigns it the default value 0.
It’s also possible to specify the arguments out of order when using named parameters. The arguments for the required parameters must always be supplied.
What is the new syntax for methods that just return a value?
static int Cube(int x) => x * x * x;
(lambda expressions)
used to be:
static int Cube(int x)
{
return x * x * x;
}








