C# Fundamentals Flashcards

1
Q

What is the CLR?

A

Common Language Runtime - works in background

  • Manages memory
  • OS and hard independence
  • Language independence; many langs
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is FCL?

A

Framework Class Library

  • library of functionality to build apps
  • large and varied
  • typically focus on specific areas (ASP.NET)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What languages fed C#?

A

Java, C++ and JavaScript

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

What is csc?

A

Visual C# Compiler - csc.exe

csc file.cs

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

What does compiler do?

A
  • Transforms C# into MSIL (MS Intermediate Language)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are “Members”?

A

Basically everything within the curly braces of a Class. Everything contained within that Class.

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

What do Class Members define?

A
  • State (a Field)

- Behavior - members that do work (Methods)

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

What does adding an “f” next to a number do?

A

Tells the program the number should be treated as a FLOAT

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

What is a Constructor?

A
  • Special methods used to initialize objects
  • All classes have an implicit constructor
  • You can explicitly define a custom constructor (or multiple)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is snippet for adding a Constructor?

A
  • “ctor” then tab tab
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are reference types?

A
  • Classes are reference types
  • Variable holds pointer value, pointer to memory
  • Multiple variables can point to same object; same point in memory
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are Access Modifiers?

A
  • public, private, etc
  • public - publically available
  • default is private
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is Encapsulation?

A
  • Hiding or not exposing some of the details of code

- Only exposing members you want to expose

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

What is static?

A
  • Use static members of class without creating an instance
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is assembly?

A
  • Compiled code in form of exe or DLL

- instructions for code to run on the CLR

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

What is Unit Testing?

A
  • VS has Unit Test Project

- Use Code to test Code

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

What is the default access modifier for a new Class?

A
  • the default is Internal

- this means the class can only be accessed within same project

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

Which attributes are used for basic C# unit testing?

A
  • [TestClass]
  • [TestMethod]
  • use Asserts
19
Q

What is a value type?

A
  • data is actually stored in memory location
  • no pointers, no references
  • value types fast, small, less resources than reference types
  • int, double, float (primitives)
20
Q

What is a struct?

A
  • create value types
  • looks like Class definition
  • abstractions that represent single value
  • generally contain small amount of data
21
Q

What is an enumeration?

A
  • creates value type

- assign numbers to labels

22
Q

What is the shortcut key to view Class/object details?

A
  • F12
23
Q

How are method parameters passed?

A
  • parameters pass by value by default
  • Ref types pass a copy of the pointer
  • Value types pass a copy of the value
  • use “ref” or “out” keywords to pass a reference instead of value
24
Q

What is Immutability?

A
  • the value of something cannot change
  • primitive types values cannot be changed
  • DateTime, string
  • example, DateTime … AddDays… must assign back to variable, can’t just run date.AddDays(1) … must assign date = date.AddDays(1);
  • string is not a value type but behaves like one
25
Q

What is an Array?

A
  • manages a collection of variables
  • always 0 indexed
  • fixed size
  • better than List if size known, otherwise List
  • Arrays are a reference type
26
Q

What are Methods?

A
  • methods define behavior
  • has access modifier, default private
  • every method has a return Type
  • zero or more parameters
  • you can use params keyword to pass unspecified number of parameters
27
Q

What are Fields?

A
  • variables of a Class
  • typically made private
  • readonly keyword allows value to be set only in Constructor
  • generally lowercase and sometimes prefixed with underscore
28
Q

What are Properties and comparison to Fields?

A
  • often used to assign/control fields
  • properties can define get/set accessor
  • property (and Method) names generally capitalized
  • autoimplemented property
    • public string Name { get; set; }
  • serialization for some frameworks will only serialize Properties and not Fields
  • shortcut “prop” tab tab
29
Q

What are Events?

A
  • another Member of a Class
  • allow Class to send notifications to other classes or objects
  • Pub/Sub
  • Events build on top of Delegates
  • Event is preferred over using Delegate directly because you can only assign using +=/-= and not NULL out all delegates
  • convention is Event takes 2 parameters - sender, arguments
  • [Label]EventArgs
30
Q

What are Delegates?

A
  • A delegate is a type that references methods
  • definition looks like a Method def
  • use += to assign multiple methods to Delegate
31
Q

What is Conditional Branching?

A
  • example IF/ELSE statements

- the code between the expressions

32
Q

What is a Ternary (or Conditional) operator?

A
  • first piece must return true/false
  • then 2 values depending on true/false
  • string pass = age > 20 ? “pass” : “fail”;
33
Q

What are code Jumping keywords?

A
  • break
  • continue
  • goto
  • return
  • throw
34
Q

When can you use a Using statement?

A
  • if the object is IDisposable
  • if it has a Dispose() method then most likely can
  • alternative to using Try/Catch/Finally and cleaning up resources in Finally
35
Q

What are the 3 pillars of OOO?

A
  • Encapsulation (the primary pillar?)
  • Inheritance
  • Polymorphism
36
Q

What is Encapsulation?

A
  • hiding details
  • classes, methods
  • just think about inputs/outputs
  • hiding complexity and building models that bring together like functionality
37
Q

What is Inheritance?

A
  • define a relation between 2 Classes
  • one Class inherits the Members of another Class
  • you can only inherit from a single Class
  • Class : BaseClass
38
Q

What is the Protected access modifier?

A
  • can access from code in Class or in code from derived Class
39
Q

What is base Class for everything in .net?

A
  • System.Object

- if Class has no base Class, it is Object

40
Q

What is Polymorphism?

A
  • means “many shapes”
  • one variable can point to different types
  • behaviors depend on which type
  • can override methods
  • method called by default is determined by the type of variable
  • if using “virtual” keyword in base class then method is determined by object type in use
41
Q

What is an Abstract Class?

A
  • cannot be instantiated, must be inherited
  • Members can be concrete or abstract
  • an abstract method in abstract Class has no implementation and must be implemented in inheriting Class
  • similar to using interface
  • abstract method implementation is implicitly virtual so must be an override
42
Q

What is an Interface?

A
  • Similar to abstract class but contains no implementation details
  • prefixed by I… IWindow, IDisposable, etc
  • main difference with abstract class is classes can only inherit single class but multiple interfaces can be inherited
43
Q

What do Partial and Curry extension methods mean?

A
  • these are somewhat complex

- these are ways to adapt the Funcs of extension methods to work with necessary parameters

44
Q

What is TPL?

A
  • Task Parallel Library
  • AsParallel() - black box linq option
  • Parallel.Invoke - run some Action without return
  • Task … tasks
  • task.ContinueWith((antecedent) => yadda yadda)
  • antecedent is the last thing to execute