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?

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
What is an Array?
- manages a collection of variables - always 0 indexed - fixed size - better than List if size known, otherwise List - Arrays are a reference type
26
What are Methods?
- 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
What are Fields?
- 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
What are Properties and comparison to Fields?
- 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
What are Events?
- 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
What are Delegates?
- A delegate is a type that references methods - definition looks like a Method def - use += to assign multiple methods to Delegate
31
What is Conditional Branching?
- example IF/ELSE statements | - the code between the expressions
32
What is a Ternary (or Conditional) operator?
- first piece must return true/false - then 2 values depending on true/false - string pass = age > 20 ? "pass" : "fail";
33
What are code Jumping keywords?
- break - continue - goto - return - throw
34
When can you use a Using statement?
- 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
What are the 3 pillars of OOO?
- Encapsulation (the primary pillar?) - Inheritance - Polymorphism
36
What is Encapsulation?
- hiding details - classes, methods - just think about inputs/outputs - hiding complexity and building models that bring together like functionality
37
What is Inheritance?
- 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
What is the Protected access modifier?
- can access from code in Class or in code from derived Class
39
What is base Class for everything in .net?
- System.Object | - if Class has no base Class, it is Object
40
What is Polymorphism?
- 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
What is an Abstract Class?
- 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
What is an Interface?
- 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
What do Partial and Curry extension methods mean?
- these are somewhat complex | - these are ways to adapt the Funcs of extension methods to work with necessary parameters
44
What is TPL?
- 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