C# Fundamentals Flashcards
What is the CLR?
Common Language Runtime - works in background
- Manages memory
- OS and hard independence
- Language independence; many langs
What is FCL?
Framework Class Library
- library of functionality to build apps
- large and varied
- typically focus on specific areas (ASP.NET)
What languages fed C#?
Java, C++ and JavaScript
What is csc?
Visual C# Compiler - csc.exe
csc file.cs
What does compiler do?
- Transforms C# into MSIL (MS Intermediate Language)
What are “Members”?
Basically everything within the curly braces of a Class. Everything contained within that Class.
What do Class Members define?
- State (a Field)
- Behavior - members that do work (Methods)
What does adding an “f” next to a number do?
Tells the program the number should be treated as a FLOAT
What is a Constructor?
- Special methods used to initialize objects
- All classes have an implicit constructor
- You can explicitly define a custom constructor (or multiple)
What is snippet for adding a Constructor?
- “ctor” then tab tab
What are reference types?
- Classes are reference types
- Variable holds pointer value, pointer to memory
- Multiple variables can point to same object; same point in memory
What are Access Modifiers?
- public, private, etc
- public - publically available
- default is private
What is Encapsulation?
- Hiding or not exposing some of the details of code
- Only exposing members you want to expose
What is static?
- Use static members of class without creating an instance
What is assembly?
- Compiled code in form of exe or DLL
- instructions for code to run on the CLR
What is Unit Testing?
- VS has Unit Test Project
- Use Code to test Code
What is the default access modifier for a new Class?
- the default is Internal
- this means the class can only be accessed within same project
Which attributes are used for basic C# unit testing?
- [TestClass]
- [TestMethod]
- use Asserts
What is a value type?
- data is actually stored in memory location
- no pointers, no references
- value types fast, small, less resources than reference types
- int, double, float (primitives)
What is a struct?
- create value types
- looks like Class definition
- abstractions that represent single value
- generally contain small amount of data
What is an enumeration?
- creates value type
- assign numbers to labels
What is the shortcut key to view Class/object details?
- F12
How are method parameters passed?
- 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
What is Immutability?
- 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
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
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
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
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
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
What are Delegates?
- A delegate is a type that references methods
- definition looks like a Method def
- use += to assign multiple methods to Delegate
What is Conditional Branching?
- example IF/ELSE statements
- the code between the expressions
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”;
What are code Jumping keywords?
- break
- continue
- goto
- return
- throw
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
What are the 3 pillars of OOO?
- Encapsulation (the primary pillar?)
- Inheritance
- Polymorphism
What is Encapsulation?
- hiding details
- classes, methods
- just think about inputs/outputs
- hiding complexity and building models that bring together like functionality
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
What is the Protected access modifier?
- can access from code in Class or in code from derived Class
What is base Class for everything in .net?
- System.Object
- if Class has no base Class, it is Object
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
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
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
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
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