C# Object Model Flashcards

1
Q
  • IDE
  • UI
  • UWP
  • XML
  • XAML
A
  • Integrated Development Environment
  • User Interface
  • Universal Windows Platform
  • Extensible Markup Language
  • Extensible Application Markup Language
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Assemblies

A
  • Libraries of compiled code
  • Located in the References folder
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
  • //
  • (/*) and (*/)
A
  • Comments
  • Comments on multiple lines. Opening and closing statements
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
  • using System;
  • using System.Collections.Generic;
  • using System.Linq;
  • using System.Text;
  • using System.Threading.Tasks;
A

Using directives that refer to namespaces

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

using Windows.UI.Popups;

A

Contains the MessageDialog class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  • Syntax
  • Semantics
A
  • Relates to format and construction
  • Relates to what statements do
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Message Box

A

Console.WriteLine();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  • Assign a value to a float variable
  • Assign a value to a long variable
  • Assign a value to a decimal variable
A
  • Add F after the value
  • Add L after the value
  • Add M after the value
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
  • Convert a string value to an integer
  • Convert a string value to a double
  • Convert a numeric value to a string
A
  • Int.Parse();
  • Double.Parse();
  • ToString();
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

String Interpolation

A
  • $”String1 {String2}”
  • $”{String1}{String2}”
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
  • Remainder (Modulus) operator
  • Not operator
  • Equality operator
  • And operator
  • OR operator
A
  • %
  • !
  • ==
  • &&
  • ||
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Associativity

A
  • *, / → left to right
  • = → right to left
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Void

A

Does not return a value

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

Cause immediate exit from a void method

A

Write return; with no expression

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

Expression-bodied method

A
  • Methods with a single line of code
  • Example: void showResult(int answer) => Console.Writeline($”The answer is {answer}”);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

C# term for variable defined by a class

A

Field

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

In a method, you must declare a variable before you can use it

A

In a class, you can declare a field can be declared after the statements that require it

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

Optional parameters

A

Simply assign them a default value

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

Short circuiting

A
  • When the first expression of a && statement is false
  • When the first expression of a || statement is true
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Switch allowed variables

A

Int, char and string variables

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

SystemException

A
  • FormatException
  • OverflowException
22
Q

Exception filters

A

Example:

catch (Exception e) when (e.GetType() != typeof(System.OutOfMemoryException))

23
Q

Refer to the minimum or maximum value of and int

A
  • int.MinValue
  • int.MaxValue
24
Q

Integer arithmetic overflow checking (int or long)

A
  • checked
    • {…
    • }
  • unchecked
    • {…
    • }
25
Throwing an exception
throw new *ExceptionType* ("Message")
26
Create an instance of a class
* Requires the new keyword * Example: * Circle c; * c = new Circle();
27
Variables declared in a method are not initialized by default
Variables declared in a class are automatically initialized to 0, false or null
28
Every class must have a constructor
* It must have the same name as the class * It is public * It initializes the fields
29
Partial class
A class that has been split into two files
30
this keyword
Refers to the field in the object
31
Static methods
* Can be accessed without creating an instance of the class in which they are contained * Can not access instance methods or instance fields defined in that same class * Are available through the lifetime of an application
32
public static fields
Are shared by all the objects of a class and can be accessed from outside the class
33
static classes
* Can only contain static members * Cannot contain any instance data or methods * Are accessed directly with the name of the class (and not the object as it is usually the case)
34
using static *class name*
Allows you to access a static member of a class without specifying the class name
35
Anonymous class
* Can contain only public fields * All fields must be initialized and cannot be static * Example: var *name* = new { Amount = 108, Message = "*string*" };
36
Value types
* int * float * double * char
37
Reference types
* class * string * object * array
38
Passing a value type as a parameter
A copy of the variable is made and the original one is unaffected
39
Passing a reference type as a parameter
The original value of the variable, class or object is modified
40
Nullable types
* Use ? to declare a nullable value type * Example: int? i = null; * Use !i.HasValue to test if the variable is null
41
Passing a parameter as *ref*
* Passes the parameter as a reference rather than a copy * Example: * name (ref i) * static void *name* (ref int i)
42
Passing a parameter as *out*
* Passes the parameter as a reference rather than a copy and initializes it * Example: * name (out i) * static void name (out int i)
43
C# enforces the assignment of values to variables
Variables can't be read if they have not been initialized
44
Stack and heap memory
* Stack * Comes into existence for the execution of a method and is then released * Contains value types * Heap * Comes into existence with the *new* keyword. Holds objects that are created * Contains reference types and nullable types
45
Boxing
* Copying an item from the stack to the heap * Example: * int i = 10; * object x = i; * Note: if you modify the value on the heap, the value on the stack will not change and vice versa
46
Cast
* Is used to verify if an object contains the specified variable type * Example: * int i = 10; * object x = i; * i = (int)x;
47
is operator
Is used to test if a variable is of a certain type
48
as operator
* Is used to cast a variable as a certain type * Example: * object x = AA * *CustomObject* test = x as *CustomObject*
49
Enumeration type
* Contains a limited set of symbolic names * Example: * enum Season { Spring, Summer, Fall, Winter }
50
Structure type
* Acts like a class but is stored in the stack * The compiler always generates a default constructor for structures
51
How to insert a backslash (C# assumes that every backslash is the start fo a special character)
* Use two backslash: \\ * Put the @ character before the entire string: @"*string*"