C# - .Net - Visual Studio
C# - .Net - Visual Studio
Net/Visual Studio
Study online at https://quizlet.com/_6to5gz
An integrated development environment created by Microsoft for
What is Visual Studio?
developing computer programs, web applications, etc.
Lines in a program beginning with the hash '#' symbol that give
What are pre-processor directives? special instructions to the compiler before the compilation process
actually starts
An open source developer platform created by Microsoft for build-
What is .NET?
ing many different types of applications
A cross platform version of the .NET framework. It has limited
What is .NET core?
capability compared to the .NET framework
A software development framework designed by Microsoft to make
programming easier. It contains a collection of class libraries (pre-
What is .NET framework? defined classes) for you to use and executes your code within the
CLR run-time environment which provides services like threading,
memory management, and exception handling.
A collection of classes [Package] which can be used in other
What is a namespace? applications. Class names declared within one namespace do not
conflict with the same class names declared in another.
First the.NET framework takes all .NET supported code (e.g., C#,
VB net, and C++) and converts it into the Microsoft Intermediate
Language (MSIL), an independent 'machine-code like' language.
MSIL is then run on the CLR, which is the virtual machine which
Can you explain the .NET framework? converts your MSIL code into 'real' machine code using the JIT
(just in time) compiler.
The reason it is called the 'just in time' compiler is because only the
MSIL needed for any particular moment is compiled into machine
code.
A CPU-independent set of instructions that can be converted to
native code by the JIT compiler.
What is Microsoft Intermediate Language (MSIL)? (Now Common
Intermediate Language CIL) .NET supported languages like C#, C++, and VBnet are all turned
into MSIL within the .NET framework and are run on the CLR
run-time environment
The virtual machine of the .NET framework which .NET programs
What is Common Language Runtime (CLR)?
are run on.
Memory management
Exception handling
What services does the CLR provide?
Garbage collection
Thread management
A compiler which is used is used as a part of the runtime execution
What is Just-In-time (JIT)?
environment. It turns CLR into machine code.
What services does the Common Language Runtime (CLR) pro- Memory Management ,Garbage Collection, Exception Handling,
vide? Common Type System
A general purpose, multi-paradigm object oriented language. It
can be used for a wide range of applications including, but not
What is C#?
limited to, windows applications, web applications, and gaming
engines
The language handles programming problems through the use
What does it mean for a programming language to be object-ori-
of classes and objects, with objects being bundles of data and
ented?
properties which act on that data
They are used to control security of a class, method, or variable
What are access specifiers in C#?
and help achieve encapsulation
The general rule of thumb is that all members are given the most
What is the default access specifier in C#? restrictive access specifier they can have by default. For example,
class fields are by default private.
1 / 18
C#/.Net/Visual Studio
Study online at https://quizlet.com/_6to5gz
By default public and abstract (no other access modifiers are
What is the default access specifier for interface members?
allowed)
What is the default access specifier for class and struct members
By default private
members?
What is the default access specifier for classes and structures? By default internal, and can only be either public or internal
What is the default access modifier for namespaces? By default public (no access modifiers allowed)
What is a solution in visual studio? A container of one or more related classes
It is contained within a solution and holds all the source code,
What is a project in visual studio? images, and data files that are compiled into an executable or
library
Value (e.g., int, float, char, byte)
What are the two types of variables in C#?
Reference (e.g., String, Object)
Value types variables directly store their value in the stack while
reference type variables store a reference address in the stack
which points to the location of where the variable's value is stored
in the heap.
What is the difference between value type and reference type? Two reference type variables can hold the same reference, and
therefore changes in one will affect the other.
Value type variables hold their own unique value, and therefore
changes in one do not affect the other (even if they hold the 'same
value'.
What are some examples of value data types? int, float, char, byte, decimal
What are some examples of reference data types? String, Object.
Methods that are associated with the class itself, not an object of
What are static methods?
the class, and therefore are called without class instantiation
What is a class? A blueprint that defines object variables and methods.
Special methods of the class which are used to assign initial
What are constructors?
values to the data members of the class.
Also known as a destructor, it is used to perform any necessary
What is a finalizer? final cleanup when a class instance is being collected by the
garbage collector
A special method inside the class used to destroy instances of that
class when they are no longer needed.
What is a destructor?
It is distinguished from the constructor by the tilde '~' symbol
The code which is developed in the .NET framework and is han-
What is managed code?
dled directly by the CLR
Code that is developed outside the .NET framework and is not
What is unmanaged code? handled by the CLR. Instead, it must be handled manually by the
programmer
When used with a base class method, it allows the method to be
What does the virtual keyword do?
overridden in a derived class
By providing the 'override' keyword in the derived class's method
How do you override a virtual method?
declaration
public override double Area()
{
Example of method overriding
// Derived implementation
}
2 / 18
C#/.Net/Visual Studio
Study online at https://quizlet.com/_6to5gz
while the virtual keyword is supposed to allow a property or
method to be changed within a derived class
[Access modifier] [Class keyword] [Identifier (i.e. class name)]
What is the syntax for class declaration?
'public class MyClass'
[access modifier] [return type] [method name] [parameters]
What is the syntax for method declaration?
public void MyMethod(int parameter1, string parameter2)
[data type] [variable name] [assignment operator] [value]
What is the syntax for variable declaration?
int i = 1;
Is C# case sensitive? Yes, this includes variable and method names
What is a field? Fields are ordinary member variables of a class
Properties are used to get and set field values (aka accessor
What is a property?
methods aka getters & setters)
Commonly known as getters and setters, they are methods used
What are accessor methods?
to access private field values
What is a method? A code block that executes a series of statements
Inheritance
Polymorphism
What are the 4 pillars of OOP?
Encapsulation
Abstraction
The ability to create a class that inherits attributes and behaviors
What is inheritance?
from an existing class
What is the benefit of inheritance? It provides for code reusability
In the derived class's declaration you provide a colon ':' and the
How is Inheritance achieved in C#?
name of the base class it is inheriting from
public class DerivedClass : BaseClass
{
Example of inheritance
//Derived class properties and methods
}
No. C# limits classes to single-inheritance, meaning each classes
inherits from a single parent class. This is done to prevent the pos-
Does C# support multiple-inheritance? Why or why not?
sible ambiguity between base class method calls (e.g. diamond
problem)
One of the four pillars of OOP which means 'having many forms'.
What is polymorphism? In particular it refers to the ability to present the same interface for
different forms
Helps promote flexibility in designs by allowing the same method
What is the benefit of polymorphism?
to have different implementations
Compile time (static)
What are the two kinds of polymorphism?
Runtime (dynamic)
It is achieved by using method overloading, i.e. defining multiple
methods with the same name but with different parameters.
What is compile time polymorphism?
It allows you to perform different tasks with the same method name
by passing different parameters
It is achieved by method overriding, i.e. using override and virtual
keywords to override a base class method by creating a derived
method with the same name and parameters to perform a different
What is runtime polymorphism? task
It allows you to perform different tasks with the same method name
by calling either the base method or derived method
3 / 18
C#/.Net/Visual Studio
Study online at https://quizlet.com/_6to5gz
It allows you to hide internal state and abstract access to it through
What is the benefit of encapsulation?
properties. It also makes code more maintainable
The process of enclosing one or more items within a 'package' and
What is encapsulation?
hiding the data in a class from other classes (data-hiding)
Through the use of access specifiers. In particular, you declare all
How is encapsulation achieved? the fields of a class private and use properties (accessor methods)
to get and set the values of these fields
The process in which only the most essential details are shown to
the user
With the parent class defined as such the child class can override
the inherited method
with the key word 'override'
Public,
Internal,
Protected,
What are the different kinds of access specifiers?
Protected internal,
Private protected,
Private
Access is not restricted anywhere, including inside the same
What does the public access specifier mean?
assembly or another assembly that references it
4 / 18
C#/.Net/Visual Studio
Study online at https://quizlet.com/_6to5gz
What does internal access specifier mean? Access is limited to the current assembly
What does protected access specifier mean? Access is limited within the class or struct and the derived class
What does protected internal access specifier mean? Access is limited to the current assembly or within derived classes
What does the private protected access specifier mean? Access is limited only to child classes within the same assembly
Accessibility is limited only inside the classes or struct in which the
What does the private access specifier mean?
member is declared. It is the least permissive access level
Protected internal means access is limited to either derived class-
What is the difference between protected internal and private
es or within the same assembly while private protected means
protected?
access is limited to only derived classes within the same assembly
What does the sealed keyword do? A keyword that stops inheritance e.g. the class can not be inherited
A keyword that create a special type of class/method that cannot
What does the abstract keyword do?
be instantiated
A purely abstract class that only contains properties and method
What is an interface? signatures. It is up to classes to provide the implementation details
for an interface, and therefore interfaces cannot be instantiated
No because they are not designed to provide any kind of specific
implementation, but they can define properties (which obtains
Can an interface contain member fields?
member fields in a roundabout way). It is still up to the class to
provide an implementation for the properties.
An interface is defined by the keyword interface and a name
starting with a capital 'I'
Example:
What is the naming convention for interfaces?
interface IEquatable<T>
{
bool Equals(T obj);
}
A special kind of class, (marked by the abstract keyword), that
cannot be instantiated, and it is designed to be inherited by other
classes. It must contain at least one abstract method, but it can
What is an abstract class?
also contain concrete methods (methods that contain an imple-
mentation in the body). It can have constructors and destructors
as well (unlike an interface).
It consists of the method name and the type of each of its formal
What makes up a method signature?
parameters. It does NOT include the return type.
Abstract:
-Can contain both abstract methods (at least 1) and concrete
methods
-Can contain constructors / destructors
-Can contain Static methods
What are the differences between an interface and an abstract -Can be partially implemented
class?
Interface:
-Can only contain abstract methods
-Does not contain constructors / destructors
-Cannot contain static methods
-Designed to be fully implemented
Are abstract methods and properties inherently virtual? Yes
No, because static methods/classes cannot be inherited or over-
Can a static method/class be abstract?
ridden
Virtual methods have an implementation and provide derived
classes the option of overriding it
What are the differences between virtual methods and abstract
methods?
Abstract methods have no implementation and derived classes
are forced to override the method
5 / 18
C#/.Net/Visual Studio
Study online at https://quizlet.com/_6to5gz
They are faster, 'light-weight' versions of classes and are defined
by the 'struct' keyword
They are value type (stored on the stack) and do not support
What is a structure?
inheritance, but they can implement interfaces
Example:
What is the difference between a parameter and an argument?
public void test(int number){}
-'int number' is a parameter
test(myNumber);
-'myNumber' is an argument
Used to indicate that a value is passed by reference
Note: The ref keyword can be used on both reference types and
value types.
void Method(ref int refArgument)
{
refArgument = refArgument + 44;
}
int number = 1;
Console.WriteLine(number);
Example of passing a value type argument by ref
Method(ref number);
Console.WriteLine(number);
// Output:
1
45
class Product
{
public Product(string name, int newID)
{
ItemName = name;
ItemID = newID;
}
ChangeByReference(ref item);
System.Console.WriteLine("Name: {0}, ID: {1}\n",
item.ItemName, item.ItemID);
}
// Output:
Name: Fasteners, ID: 54321
Name: Stapler, ID: 99999
(used on parameters) Causes arguments to be passed by refer-
What does the out parameter modifier do? ence, but it does not require that the variable be initialized before
it is passed
(Used on parameters) Causes arguments to be passed by refer-
What does the in parameter modifier do? ence, but it does not allow the argument to be modified within the
called method
A variable that cannot be changed once it is declared (i.e. value
set at compile time)
What is a constant?
Created with the 'const' keyword
Used to create a variable whose value cannot be edited except at
What does the readonly keyword do?
run time (within the constructor)
-Classes are reference types, structs are value types
-Classes use the new keyword for creating instances while struct
can create an instance without the new keyword
-Two variables in a class can reference the same object and any
operation on one object would affect the other, while each variable
in a struct contains its own copy of data and any operation of one
variable can not affect another variable
Converting value type to reference types
What is boxing
Implicit
Converting reference types to value types
What is unboxing?
explicit
When you would like to force derived classes to implement meth-
Why would you want to use an abstract class (or method)?
ods, usually unique to them
specialized classes that hold many values or objects in a specific
series.
What are collections?
e.g.
ArrayList, HashTable, SortedList, Stack, Queue
7 / 18
C#/.Net/Visual Studio
Study online at https://quizlet.com/_6to5gz
A collection that specifies the datatypes of its members and so
boxing and unboxing is not required.
What are generic collections?
e.g.
List<T>, Dictionary, SortedList, Stack, Queue
Collections of objects which don't specify the datatype of its mem-
bers.
What are non-generic collections?
e.g. ArrayList, SortedList, Stack, Queue
A generic collection of key-and-value pairs that are organized
based on the hash code of the key.
What is a dictionary?
It specifies datatypes of both its keys and values
A non-generic collection of key-and-value pairs that are organized
based on the hash code of the key. It uses the key to access the
What is a hashtable? elements in the collection.
What is 'var' used for? It instructs the compiler to infer the type of the variable based on
the expression from the right side of the initialization statement (at
compile time)
What is an exception? A runtime error that interrupts the normal flow of an application.
8 / 18
C#/.Net/Visual Studio
Study online at https://quizlet.com/_6to5gz
IOException
-Related to file reading and writing
IndexOutOfRangeException
-Occurs when a method refers to an array index out of the arrays
range
What are some examples of exceptions?
NullReferenceException
-Occurs whenever you try to reference a null object
DivideByZeroException
-Occurs whenever you try to divide a number by zero
A process to handle runtime errors.
What is exception handling? Why do it?
We perform it so that the normal flow of the application can be
maintained even after runtime errors.
By placing code that might throw exceptions into try blocks, han-
dling exceptions within catch blocks, and wrapping up with final-
How do you handle exceptions in C#?
ly blocks to execute cleanup code regardless if exceptions are
thrown or not.
It can be used to re-throw caught exceptions and to manually throw
What does the throw keyword do?
new exceptions by using the new keyword
Allows you to specify a conditional clause for each catch block.
What are exception filters? Using exception filters let you have more control over how you
handle specific exceptions
A statement which ensures that unmanaged objects are properly
disposed of once the using block is exited (given that the objects
implement the IDisposable interface).
What is 'using'?
The compiler implicitly converts the using block into a try finally
block.
9 / 18
C#/.Net/Visual Studio
Study online at https://quizlet.com/_6to5gz
Composing multiple delegates together into a single delegate by
What does it mean to multicast a delegate?
using the '+' operator
Allow methods to be passed as an argument.
What are the advantage of delegates?
Allow multiple methods to be called on a single event.
A delegate can refer to a method which has the same signature
and return type as that of the delegate. For example:
What is a dynamic linked library (DLL) ? .dll's can be created in Visual Studio by building a project.
If you want to use a DLL then just add a reference for the DLL file
in your project and then add it to the namespace
A class that you can use in situations where you need to make
repeated modifications to a string without creating new string
What is StringBuilder? objects.
11 / 18
C#/.Net/Visual Studio
Study online at https://quizlet.com/_6to5gz
public delegate void Print(int val);
Console.WriteLine(result);
}
}
A generic delegate that returns a true or false value. It can be used
What is 'predicate'?
to store references to methods which return a boolean
static bool IsUpperCase(string str)
{
return str.Equals(str.ToUpper());
}
Console.WriteLine(result);
}
Checking that your code is working as expected by breaking down
What is unit testing? the functionality of your program into small discrete units that you
can test individually
AAA
Arrange
- Setup the code that is required for the test and setup your
expectations
What is the generic methodology used in unit testing?
Act
- Call the method that you want to test
Assert
- Verify whether or not the expectations you set were met
XUnit
What are the two extensions in unit testing?
NUnit
12 / 18
C#/.Net/Visual Studio
Study online at https://quizlet.com/_6to5gz
What is the 'is' keyword used for? To check if a variable is of a given type
Attempts to cast a variable to another type, and if it fails it will return
What is the 'as' keyword used for?
null
Used to inform the JIT compiler that the value of the variable might
What does 'volatile' mean?
be changed by multiple threads
Const: once declared it cannot be changed(compile time). read-
What are the differences between const and read-only?
only: can only be changed by a constructor (runtime)
What is the namespace for serialization? System.Runtime.Serialization;
Assigning multiple class objects to a single delegate(Delegate
What is a multicast delegate?
allMethods = delegate1 + delegate2; )
What class do all classes in C# inherit from? System.Object
Begin by catching the more specific exceptions and then work
towards more generic exceptions.
How should you order your catch blocks? The reason for this is because once a catch block catches an
exception the rest are ignored, and handling generic exceptions
first might not give you everything you need to know to truly solve
the exception
Code that you want to be executed whether or not an exception
What kind of code would you put into a finally block? is thrown. Usually you will place 'cleanup' code that takes care of
unmanaged code here
Code that uses pointers
What are some examples of unmanaged code?
Any code that is not supported by the CLR runtime environment
In:
Used to pass readonly arguments by reference to a method
Out:
Used to pass arguments by reference to a method, but the argu-
What are the differences between in, out, and ref
ment does not need to be initialized
Ref:
Used to pass arguments by reference to a method, but the argu-
ment does need to be initialized
Yes, and this means that it has a type system that is checked at
compile time.
Is C# statically typed? If so, what does that mean?
The workaround is to use the 'dynamic' keyword
No, it supports a multiple different classes inheriting the same
Does C# support multiple inheritance?
class, however, one class cannot inherit multiple classes.
Can an interface extend another interface in C#? yes
An acronym for the first five object-oriented design principles. They
are:
Examples:
What are creational design patterns?
Abstract Factory
-Creates an instance of several families of classes
Singleton
-A class of which only a single instance can exist (logger)
Define relationships between classes or objects
What are structural design patterns?
Examples:
Define manners of communication between classes and objects.
Examples:
What are behavioral design patterns?
Mediator
-Defines simplified communication between classes
Observer
-A way of notifying change to a number of classes
The process used design, develop, and test high quality software
that meets customer expectations
Phases:
Planning
-Gather information about the requirements for the software you
are building and then propose a plan for moving forward
Analysis/Design
What is the software development life cycle (SDLC)? -Design the best possible structure for the software product
Building
-Begin actual development
Testing
-Test the product and see if everything is working as expected
Deployment
-Release the product to the customer/market after all required
testing is done
A software development model that entails going through all the
steps of the SDLC without any input from the end user, usually
What is waterfall development?
takes place over a long period of time
14 / 18
C#/.Net/Visual Studio
Study online at https://quizlet.com/_6to5gz
You would use this development model when you to have the
product fully operational and complete when you present it to the
end user, e.g. military aircraft
A software development methodology that delivers partial func-
tionality in rapid iterations, requiring frequent communication be-
tween the developers and the customer
The key principle is that the customer can change their minds
What is scrum? about what they want at any point during development.
Process:
ADO.NET
1) Connection
2) Command
3) Execute
Any service that communicates data over that web
What are web services (API)
E.g. REST and SOAP
An XML-based messaging protocol for exchanging information
What is Simple Object Access Protocol (SOAP)?
among computers
Actual document that describes the details of the SOAP request.
This is written in XML format.
What is a SOAP envelope?
Has a header and a body similar to an HTML webpage.
Connect with
An architectural style for communication between a client and a
server which allows each one to be done independently without
knowing about the other.
What is representational state transfer (REST)?
This means you can change code on the client side without
affecting the server side, and vice versa.
What are the differences between SOAP and REST
15 / 18
C#/.Net/Visual Studio
Study online at https://quizlet.com/_6to5gz
SOAP requires XML formatting while REST supports multiple data
formats such as HTML, JSON, XML, and plain text
How many interfaces can a class implement? A class can implement any number of interfaces
The 'endpoint'...
WebRequest wr = WebRequest.Create(siteUri);
What is WebRequest? A class in the System.Net namespace used to make a SOAP calls
What is Web Services Description Language (WSDL)? WSDL documents describe a web service and is written in XML.
The volatile keyword informs the compiler that the designated
What does the volatile keyword mean? variable can have its variable changed by another thread during
run time
The waterfall methodology ensures that the software is completely
developed before being deployed.
Distinguish the difference between waterfall and agile methodol-
In the agile framework parts and components of a given product
ogy
are completed during sprints and are deployed. This allows im-
mediate feedback from end users and any bugs/defects can be
addressed in a following sprint
Use the System.Data.SqlClient namespace
16 / 18
C#/.Net/Visual Studio
Study online at https://quizlet.com/_6to5gz
What is the keyword 'using' doing? Implicitly creates a 'try/finally' block for handling unmanaged code
The step out (shift + f11) feature in debugger mode allows you to
'step out' of the function that you may have 'stepped into'
What is 'step out'
This command executes the rest of the current function and breaks
when the function return is completed.
You can use the Visual Studio provided unit tester by declaring
the namespace, specifying [TestClass] & [TestMethod] attributes
How can you unit test in visual studio? when testing classes and methods respectively
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace BankTests
{
[TestClass]
public class BankAccountTests
Example unit test {
[TestMethod]
public void TestMethod1(){}
}
}
If you have any I/O-bound needs (such as requesting data from
a network or accessing a database), you'll want to utilize asyn-
When/why would you utilize asynchronous programming? chronous programming. You could also have CPU-bound code,
such as performing an expensive calculation, which is also a good
scenario for writing async code.
using System.Threading;
using Systme.Threading. Tasks;
class ThreadTest
{
static void Main()
{
Thread t = new Thread(WriteY);
// Kick off a new thread
t.Start();
// running WriteY()
// Simultaneously, do something on the main thread.
for (int i = 0; i < 10000000; i++)
{
Multi-Threading code snippet Console.Write("x");
Console.ReadLine();
}
}
17 / 18
C#/.Net/Visual Studio
Study online at https://quizlet.com/_6to5gz
var designates the type at compile time whereas dynamic evalu-
ates the type at run time
Shorthand notation for if/else statements
What is a ternary operator? The first argument takes a comparison argument, the second is
the result upon a true comparison, and the third is the result upon
a false comparison
What are nullable types? They allow you to assign null to a value type variable.
Nullable type example Nullable<int> i = null;
What is HttpClient? A class that can be used to make REST calls
If you are performing an iteration on a collection or array, it allows
What does the 'yield' contextual keyword do? you to maintain the position/value of the iterator in which yield is
used
POST
GET
PUT
DELETE
What are the HTTP methods used for CRUD operations?
Note: CRUD operations:
Create(POST)
Read(GET)
Update(PUT)
Destroy(DELETE)
Simple Object Access Protocol.
18 / 18