Basics Flashcards

1
Q

Define method.

A

A method performs an action in a series of statements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Define statement block

A

a pair of braces containing zero or more statements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is an argument.

A

An argument is data passed to a method as a parameter.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

C# recognizes a method called ______ as signaling the default entry point of execution.

A

Main

static int Main(string[] args) { . . . }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

List the main types of functions supported by C#.

A

constructors, methods, operators, properties, events, indexers, and finalizers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

At the outermost level of a program, types are organized into _______.

A

namespaces

The using directive is used to make a namespace available to an application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

The C# compiler compiles source code, specifies as a set of files with the .cs extension, into an _______.

A

assembly.

An assembly is the unit of packing and deployment in .NET and can be either an application or a library.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the name of the C# compiler?

A

csc.exe

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is an Identifier?

A

Iderntifiers are names that programmers choose for their classes, methods, variables, and so on.

An identifier must be a whole word, made up of Unicode characters starting with a letter or underscore and are case-sensitive.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a keyword?

A

Keywords are names that mean something special to the compiler and are reserved, which means they can not be used as an identifier.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

List all of the keywords

A
abstract
as
base
bool
break
byte
case
catch
char
checked
class
const
continue
decimal
default
delegate	do
double
else
enum
event
explicit
extern
false
finally
fixed
float
for
foreach
goto
if
implicit	in
int
interface
internal
is
lock
long
namespace
new
null
object
operator
out
override
params
private	protected
public
readonly
ref
return
sbyte
sealed
short
sizeof
stackalloc
static
string
struct
switch
this
throw	true
try
typeof
uint
ulong
unchecked
unsafe
ushort
using
virtual
void
volatile
while
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Is it possible to use a keyword as an identifier? If so, how?

A

It is possible to use a keyword as an identifier by qualifying it with the @ prefix.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Is @varName == varName?

A

The @ symbol doesn’t form part of the identifier itself so @varName is the same as varName.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a literal?

A

Literals are primitive pieces of data lexically embedded into the program and also known as fixed values.

It is essentially a language type with an associated value. int dayInMonth = 9;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a punctuator?

A

A punctuator help demarcate the structure of a program.Common punctuators include: { } [ ] ‘ “ ;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is an operator?

A

An operator transforms and combines expressions. Common operators include * / + - % = ( )

17
Q

What is a type?

A

A type defines the blueprint for a value

18
Q

Which predefined types in C# are value types?

A

Numeric: - signed integer(sbyte, short, int, long), unsigned integer ( byte, ushort, uint, ulong), real number ( float, double, decimal ); Logical: -bool; Character: - char

19
Q

Which predefined types in C# are reference types?

A

String & Object

20
Q

List the Numeric suffixes

A
F   float        float f = 1.0F;
D   double   double d = 1D;
M  decimal   deciimal d = 1.0M;
U   uint          uint = 1U;
L    long        long i = 1L;
UL  ulong       ulong i = 1UL; 

The suffixes U and L are rarely necessary, because the uint, long, and ulong types can nearly always be either inferred or implicitly converted from int.

The F and M suffixes are the most useful and should always be applied when specifying float or decimal literals. Without the F suffix, the following line would not compile, because 4.5 would be inferred to be of type double, which has no implicit conversion to float:

float f = 4.5F;

21
Q

True or False: When using ==, a NaN value is never wqual to another value, even another NaN value:

A

True

22
Q

List the escape characters

A
Char	Meaning                  Value
\'	        Single quote	         0x0027
\"	         Double quote	 0x0022
\\	         Backslash	         0x005C
\0	         Null	                 0x0000
\a	         Alert	                 0x0007
\b	         Backspace	         0x0008
\f	         Form feed	         0x000C
\n	         New line	         0x000A
\r	         Carriage return	 0x000D
\t	         Horizontal tab	 0x0009
\v	         Vertical tab             0x000B
23
Q

True or False:

Objects are stored in memory on the Stack and variables/parameters are stored on the Heap.

A

False:

Variables and parameters are stored on the Stack which grows and shrinks as they these types are allocated and deallocated; while Objects are created on the Heap.

24
Q

Default Values

All type instances have a default value. List them.

A
Type					Default value
All reference types		null
All numeric types			0
enum types				0
char type				'\0'
bool type				false
25
Q

You can control how parameters are passed with the ref and out modifiers:

A

Parameter modifier Passed by Variable must be definitely assigned

(None) Value Going in
ref Reference Going in
out Reference Going out

26
Q

True or False:

The out modifier is most commonly used to get multiple values out of a function.

A

True.

27
Q

From C# 7, you can declare variables on the fly when calling methods with out parameters.

A

static void Main()
{
Split (“Stevie Ray Vaughan”, out string a, out string b);
Console.WriteLine (a); // Stevie Ray
Console.WriteLine (b); // Vaughan
}

28
Q

What is the null coalescing operator and how does it work?

A

The ?? operator is the null coalescing operator. It says “If the operand to the left is non-null, give it to me; otherwise, give me a default value.”

For example:

string s1 = null;
string s2 = s1 ?? “nothing”; // s2 evaluates to “nothing”

29
Q

What is the null-conditional operator and how does it work?

A

The ?. operator is the null-conditional or “Elvis” operator (after the Elvis emoticon), and was introduced in C# 6. It allows you to call methods and access members just like the standard dot operator, except that if the operand on the left is null, the expression evaluates to null instead of throwing a Null​ReferenceException:

System.Text.StringBuilder sb = null;
string s = sb?.ToString(); // No error; s instead evaluates to null