C#/.Net/Visual Studio

Ace your homework & exams now with Quizwiz!

What is scrum?

An implementation of Agile development The key principle is that the customer can change their minds about what they want at any point during development. There is a strong focus on working in teams in order to deliver products quickly

What is Visual Studio?

An integrated development environment created by Microsoft for developing computer programs, web applications, etc.

What is the naming convention for interfaces?

An interface is defined by the keyword interface and a name starting with a capital 'I' Example: interface IEquatable<T> { bool Equals(T obj); }

What is a Task?

An object that represents some work that should be done, and is a higher level concept than a thread.

What is .NET?

An open source developer platform created by Microsoft for building many different types of applications

What does await mean?

An operator that is applied to a task in an asynchronous method to suspend the execution of the method until the awaited task completes

What does the in parameter modifier do?

(Used on parameters) Causes arguments to be passed by reference, but it does not allow the argument to be modified within the called method

What does the out parameter modifier do?

(used on parameters) Causes arguments to be passed by reference, but it does not require that the variable be initialized before it is passed

What are the differences between a structure and a class?

-Classes are reference types, structs are value types - structs are used in small programs -Classes can contain constructors/destructor while structs cannot -Classes use the new keyword for creating instances while struct can create an instance without the new keyword -A class can inherit from another class while a struct cannot (though it can implement an interface) -A class can be a base class while a struct cannot -Members of a class can be virtual or abstract while struct's members cannot -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

What are the two components of MSIL?

.dll files and .exe files

Examples of anonymous methods

// C# 2.0: A delegate can be initialized with inline code, called an "anonymous method." This method takes a string as an input parameter. TestDelegate testDelB = delegate(string s) { Console.WriteLine(s); }; // C# 3.0. A delegate can be initialized with a lambda expression. The lambda also takes a string as an input parameter (x). The type of x is inferred by the compiler. TestDelegate testDelC = (x) => { Console.WriteLine(x); };

What is Microsoft Intermediate Language (MSIL)? (Now Common Intermediate Language CIL)

A CPU-independent set of instructions that can be converted to native code by the JIT compiler. .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

What is the single responsibility principle?

A SOLID principle that states a single class should be responsible for only one task.

What is the Liskov substitution principle?

A SOLID principle that states that if any part of a program is using a Base class then the reference to that base class can be replaced with a derived class without affecting the functionality of the module

What is the open closed principle?

A SOLID principle that states that you should write code that doesn't have to be changed every time the requirements change. In particular, base classes should be created with only required functionality, because doing so ensures that they will not have to be modified in the future (closed for modification). On the other hand, derived classes should be 'open for modification'.

What is the dependency inversion principle?

A SOLID principle that states the details should depend on abstractions, and not the other way around.

What is the interface segregation principle?

A SOLID principle that states you should make create fine-grained (specific) interfaces which do not force clients (implementation classes) to implement methods that they do not use.

What is a lambda expression?

A block of code that is treated as an object. It can be passed as an argument to a method and returned by method calls. It uses the => (lambda declaration operator) to separate the parameter list (left side of lambda declaration) from its executable code (right side of lambda declaration)

What is a class?

A blueprint that defines object variables and methods.

What are breakpoints?

A breakpoint indicates where Visual Studio should suspend your running code so you can take a closer look at the values of variables, the behavior of memory, or whether or not a branch of code is getting run.

How many interfaces can a class implement?

A class can implement any number of interfaces

What is WebRequest?

A class in the System.Net namespace used to make a SOAP calls

What is HttpClient?

A class that can be used to make REST calls

What is a static class?

A class that can't be instantiated. Created using the "static" keyword. Can contain static members only

What is XMLSerializer?

A class that serializes and deserializes objects into and from XML documents

What is StringBuilder?

A class that you can use in situations where you need to make repeated modifications to a string without creating new string objects. StringBuilder objects are in a sense dynamic and mutable strings.

What is BinaryFormatter?

A class used to serialize and deserialize objects into binary format

What is a method?

A code block that executes a series of statements

What is a namespace?

A collection of classes [Package] which can be used in other applications. Class names declared within one namespace do not conflict with the same class names declared in another.

What are generic collections?

A collection that specifies the datatypes of its members and so boxing and unboxing is not required. e.g. List<T>, Dictionary, SortedList, Stack, Queue

How do you create a delegate?

A delegate can refer to a method which has the same signature and return type as that of the delegate. For example: delegate int NumberChanger(int n); public static int AddNum(int p) { num += p; return num; } public static int MultNum(int q) { num *= q; return num; } NumberChanger nc1 = new NumberChanger(AddNum); NumberChanger nc2 = new NumberChanger(MultNum);

What is method overriding?

A derived class being able to have a different method implementation of the core class.

What is an assembly?

A file that is automatically generated by the compiler upon successful compilation of every .NET application which contains Common Intermediate Language (CIL) code. Example: .dll files

What is a callback function?

A function that will be called when a process is done executing a certain task. Often times callback functions are just functions that are passed as an argument to another function.

What is C#?

A general purpose, multi-paradigm object oriented language. It can be used for a wide range of applications including, but not limited to, windows applications, web applications, and gaming engines

What is a dictionary?

A generic collection of key-and-value pairs that are organized based on the hash code of the key. It specifies datatypes of both its keys and values

What is an action?

A generic delegate that does not return a value. It can be used to reference method that has a void return type

What is 'func'?

A generic delegate that returns a single value. It can be used to store references to methods which have a single return type

What is 'predicate'?

A generic delegate that returns a true or false value. It can be used to store references to methods which return a boolean

What is a collection?

A group of objects. Examples include ArrayList, List, HashTable, and Dictionary

What does the abstract keyword do?

A keyword that create a special type of class/method that cannot be instantiated

What does the sealed keyword do?

A keyword that stops inheritance e.g. the class can not be inherited

What is a dynamic linked library (DLL) ?

A library that contains functions and code which can be used by more than one program at a time. .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

What are enums?

A list of named integer constants, and they can be defined by using the 'enum' keyword

What does async mean?

A modifier used to declare a method as asynchronous, which means you can move on to other methods before the async method is finished

What is a hashtable?

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 elements in the collection. Does not specify datatypes

What is the difference between a parameter and an argument?

A parameter is a variable in a method definition, while an argument is the actual data that you pass into the method's parameter's when using that method Example: public void test(int number){} -'int number' is a parameter test(myNumber); -'myNumber' is an argument

What is a scrum master?

A person who facilitates the work performed within scrum development

What is exception handling? Why do it?

A process to handle runtime errors. We perform it so that the normal flow of the application can be maintained even after runtime errors.

What is an interface?

A purely abstract class that only contains properties and method signatures. It is up to classes to provide the implementation details for an interface, and therefore interfaces cannot be instantiated

What is Linq?

A query syntax that can be used to retrieve data from different kinds of sources it uses SQL like keywords such as 'select' 'from' and 'where'

What is an exception?

A runtime error that interrupts the normal flow of an application.

ADO.NET

A service in the .NET framework which provides access to data sources such as SQL Server Process: 1) Connection 2) Command 3) Execute

What is a Thread?

A small set of executable instructions. You can run tasks asynchronously

What is .NET framework?

A software development framework designed by Microsoft to make programming easier. It contains a collection of class libraries (predefined 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.

What is agile development?

A software development methodology that delivers partial functionality in rapid iterations, requiring frequent communication between the developers and the customer SaaS (Software as a Service) products (e.g. email apps and bike rental apps) are often handled using agile development. It's best to get a functional app out as soon as possible, and then continually add/enhance the app as needed. A great example of a product that can benefit from agile development are Software As A Service(SaaS) products...such as an email app, a bike rental app...etc...by having a minimal functional app on the market developers can continually enhance the existing app and add new features as needed

What is waterfall development?

A software development model that entails going through all the steps of the SDLC without any input from the end user, usually takes place over a long period of time 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

What is an abstract class?

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 also contain concrete methods (methods that contain an implementation in the body). It can have constructors and destructors as well (unlike an interface).

What is a destructor?

A special method inside the class used to destroy instances of that class when they are no longer needed. It is distinguished from the constructor by the tilde '~' symbol

What is 'using'?

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). The compiler implicitly converts the using block into a try finally block. One example of a class that goes within a using block is System.IO

What is LINQ?

A structured query syntax in C# (kind of like SQL) that is used to retrieve data from things like databases and collections

What is selenium?

A tool that automates browsers and user events

What is smoke testing?

A type of software testing that aims to ensure that most of the important functions of an application work. The result of smoke testing determines if a build is stable enough to proceed with further testing

What is a constant?

A variable that cannot be changed once it is declared (i.e. value set at compile time) Created with the 'const' keyword

What is the generic methodology used in unit testing?

AAA Arrange - Setup the code that is required for the test and setup your expectations Act - Call the method that you want to test Assert - Verify whether or not the expectations you set were met

What is ADO.net?

ADO.NET is a data access technology from the Microsoft .NET Framework that provides communication between relational and non-relational systems through a common set of components.[1]

What are the differences between an interface and an abstract class?

Abstract: -Can contain both abstract methods (at least 1) and concrete methods -Can contain constructors / destructors -Can contain Static methods -Can be partially implemented Interface: -Can only contain abstract methods -Does not contain constructors / destructors -Cannot contain static methods -Designed to be fully implemented

What does the private protected access specifier mean?

Access is limited only to child classes within the same assembly

What does internal access specifier mean?

Access is limited to the current assembly

What does protected internal access specifier mean?

Access is limited to the current assembly or within derived classes

What does protected access specifier mean?

Access is limited within the class or struct and the derived class

What does the public access specifier mean?

Access is not restricted anywhere, including inside the same assembly or another assembly that references it

What does the private access specifier mean?

Accessibility is limited only inside the classes or struct in which the member is declared. It is the least permissive access level

What are the different types of generic delegates?

Action, func, and predicate.

What is a SOAP envelope?

Actual document that describes the details of the SOAP request. This is written in XML format. Has a header and a body similar to an HTML webpage. Connect with

How do you make a class/object serializable?

Add the [Serializable] attribute right before the class declaration

What are the advantage of delegates?

Allow methods to be passed as an argument. Allow multiple methods to be called on a single event.

What are exception filters?

Allows you to specify a conditional clause for each catch block. Using exception filters let you have more control over how you handle specific exceptions

What is a class library?

Also known as a Dynamic Link Library (DLL) or 'assembly' It is a collection of pre-written class which can be used in any program by importing/referencing the file

What is a finalizer?

Also known as a destructor, it is used to perform any necessary final cleanup when a class instance is being collected by the garbage collector

What are SOLID Design principles?

An acronym for the first five object-oriented design principles. They are: 1) Single Responsibility Principle 2) Open Closed Principle 3) Liskov Substitution Principle 4) Interface Segregation Principle 5) Dependency Inversion Principle

What is representational state transfer (REST)?

An architectural style for communication between a client and a server which allows each one to be done independently without knowing about the other. This means you can change code on the client side without affecting the server side, and vice versa.

What are web services (API)

Any service that communicates data over that web E.g. REST and SOAP

What is a multicast delegate?

Assigning multiple class objects to a single delegate(Delegate allMethods = delegate1 + delegate2; )

What is the 'as' keyword used for?

Attempts to cast a variable to another type, and if it fails it will return null

How should you order your catch blocks?

Begin by catching the more specific exceptions and then work towards more generic exceptions. 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

What are the two types of serialization?

Binary Serialization and XML Serialization

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 specifier for class and struct members members?

By default private

What is the default access modifier for namespaces?

By default public (no access modifiers allowed)

What is the default access specifier for interface members?

By default public and abstract (no other access modifiers are allowed)

How do you handle exceptions in C#?

By placing code that might throw exceptions into try blocks, handling exceptions within catch blocks, and wrapping up with finally blocks to execute cleanup code regardless if exceptions are thrown or not.

How do you override a virtual method?

By providing the 'override' keyword in the derived class's method declaration

How are callback functions made possible in C#?

By storing a function address inside a delegate variable and then pass that delegate as a parameter to a method

What is unit testing?

Checking that your code is working as expected by breaking down the functionality of your program into small discrete units that you can test individually

What is unmanaged code?

Code that is developed outside the .NET framework and is not handled by the CLR. Instead, it must be handled manually by the programmer

What kind of code would you put into a finally block?

Code that you want to be executed whether or not an exception is thrown. Usually you will place 'cleanup' code that takes care of unmanaged code here

What are non-generic collections?

Collections of objects which don't specify the datatype of its members. e.g. ArrayList, SortedList, Stack, Queue

What are the two kinds of polymorphism?

Compile time (static) Runtime (dynamic)

What does it mean to multicast a delegate?

Composing multiple delegates together into a single delegate by using the '+' operator

What are the differences between const and read-only?

Const: once declared it cannot be changed(compile time). readonly: can only be changed by a constructor (runtime)

What is unboxing?

Converting reference types to value types explicit

What is boxing

Converting value type to reference types Implicit

What are behavioral design patterns?

Define manners of communication between classes and objects. Examples: Mediator -Defines simplified communication between classes Observer -A way of notifying change to a number of classes

What are structural design patterns?

Define relationships between classes or objects Examples:

What are creational design patterns?

Design patterns that deal with object creation Examples: Abstract Factory -Creates an instance of several families of classes Singleton -A class of which only a single instance can exist (logger)

What are the advantages of LINQ?

Developers don't have to learn a new query language for each type of data source they want to query from. It reduces the amount of code to be written as compared to traditional approaches. The code is easy to read and understand You can retrieve data in different shapes (i.e. data shaping).

Why would you want to use generics?

Faster than using objects because it avoids boxing/unboxing Allows you to write code which is type-safe, i.e. a List<string> is guaranteed to be a list of strings The compiler can perform compile-time checks on generics for type safety, e.g. restrict you from trying to put an int into a list of strings?

Can you explain the .NET framework?

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 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.

What datatypes are there in C#?

Following are different Value Data Types in C# programming language : a) Signed and Unsigned Integral Types b) Floating point types c) Decimal Type d) Character Type e) Boolean Type f) Struct g) Enumerators

What are delegates?

Function pointers. They are a reference type variable that holds the reference to a method.

What is method overloading?

Having multiple methods with the same name but different parameter datatypes or number

What is the benefit of polymorphism?

Helps promote flexibility in designs by allowing the same method to have different implementations

What are some examples of exceptions?

IOException -Related to file reading and writing IndexOutOfRangeException -Occurs when a method refers to an array index out of the arrays range NullReferenceException -Occurs whenever you try to reference a null object DivideByZeroException -Occurs whenever you try to divide a number by zero

What does the 'yield' contextual keyword do?

If you are performing an iteration on a collection or array, it allows you to maintain the position/value of the iterator in which yield is used

When/why would you utilize asynchronous programming?

If you have any I/O-bound needs (such as requesting data from a network or accessing a database), you'll want to utilize asynchronous programming. You could also have CPU-bound code, such as performing an expensive calculation, which is also a good scenario for writing async code.

How do you override an inherited method within the derived class?

If you wanted a child/derived class to be able to override a method from the parent/base class then firstly the parent class must be/have an: a) An abstract class with an abstract method or b) Have an accessible method that has been declared 'virtual' With the parent class defined as such the child class can override the inherited method with the key word 'override'

What are the two kinds of typecasting?

Implicit Type Casting: automatic type conversion long l = i; float f = l; Explicit: double d = 765.1; int i = (int)d;

What is the keyword 'using' doing?

Implicitly creates a 'try/finally' block for handling unmanaged code

How is Inheritance achieved in C#?

In the derived class's declaration you provide a colon ':' and the name of the base class it is inheriting from

What are the differences between in, out, and ref

In: Used to pass readonly arguments by reference to a method Out: Used to pass arguments by reference to a method, but the argument does not need to be initialized Ref: Used to pass arguments by reference to a method, but the argument does need to be initialized

What are the 4 pillars of OOP?

Inheritance Polymorphism Encapsulation Abstraction

What is IEnumerable<T>?

Interface that, if implemented, allows for the use of foreach loops and iteration over generic collections

What is IEnumerable?

Interface that, if implemented, allows for the use of foreach loops and iteration over non-generic collections

What is the benefit of encapsulation?

It allows you to hide internal state and abstract access to it through properties. It also makes code more maintainable

What does the throw keyword do?

It can be used to re-throw caught exceptions and to manually throw new exceptions by using the new keyword

What makes up a method signature?

It consists of the method name and the type of each of its formal parameters. It does NOT include the return type.

What is runtime polymorphism?

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 task It allows you to perform different tasks with the same method name by calling either the base method or derived method

What is compile time polymorphism?

It is achieved by using method overloading, i.e. defining multiple methods with the same name but with different parameters. It allows you to perform different tasks with the same method name by passing different parameters

Why would you use an enum?

It is best to use enumerators when you find yourself needing to use something that has distinctly defined values that are not subject to change. A great example is days in a week

What are some characteristics of a static constructor?

It is called automatically by the CLR before the first instance of the class is created It does not take access modifiers or have any parameters It cannot access any non-static data member of any class A class can only have one static constructor It cannot be inherited or overloaded

What is a project in visual studio?

It is contained within a solution and holds all the source code, images, and data files that are compiled into an executable or library

What is the 'this' keyword used for?

It is used to refer to the current instance of the class Pass an object as a parameter to other methods

What does the partial keyword do?

It provides the ability to implement the functionality of a single class into multiple files, and all these files are combined into a single class at compile time

What does LINQ stand for?

Language Integrated Query

What are pre-processor directives?

Lines in a program beginning with the hash '#' symbol that give special instructions to the compiler before the compilation process actually starts

What services does the Common Language Runtime (CLR) provide?

Memory Management ,Garbage Collection, Exception Handling, Common Type System

What services does the CLR provide?

Memory management Exception handling Garbage collection Thread management

What are static methods?

Methods that are associated with the class itself, not an object of the class, and therefore are called without class instantiation

What are anonymous methods?

Methods without a name. Lambda expressions can serve as an anonymous method

Can an interface contain member fields?

No because they are not designed to provide any kind of specific implementation, but they can define properties (which obtains member fields in a roundabout way). It is still up to the class to provide an implementation for the properties.

Can you use the virtual modifier on a static property or method?

No, it is an error to do so because the static keyword denotes something that does not change across all instances of a class, while the virtual keyword is supposed to allow a property or method to be changed within a derived class

Does C# support multiple inheritance?

No, it supports a multiple different classes inheriting the same class, however, one class cannot inherit multiple classes.

Does C# support multiple-inheritance? Why or why not?

No. C# limits classes to single-inheritance, meaning each classes inherits from a single parent class. This is done to prevent the possible ambiguity between base class method calls (e.g. diamond problem)

Nullable type example

Nullable<int> i = null;

What is polymorphism?

One of the four pillars of OOP which means 'having many forms'. In particular it refers to the ability to present the same interface for different forms

What are the HTTP methods used for CRUD operations?

POST GET PUT DELETE Note: CRUD operations: Create(POST) Read(GET) Update(PUT) Destroy(DELETE)

What is deserialization?

Process of taking the serialized object and translating it to its former state

What is parallel programming?

Program model where the execution is broken up into pieces that will be done at the same time by different cores, processors, or computers

What is a property?

Properties are used to get and set field values (aka accessor methods aka getters & setters)

What is the difference between protected internal and private protected?

Protected internal means access is limited to either derived classes or within the same assembly while private protected means access is limited to only derived classes within the same assembly

What are the different kinds of access specifiers?

Public, Internal, Protected, Protected internal, Private protected, Private

What is a ternary operator?

Shorthand notation for if/else statements 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 is SOAP?

Simple Object Access Protocol. A protocol where everything is sent in xml format with a header/body/footer, all placed in what is called the 'envelope'. Can work with any application layer protocol, such as HTTP, TCP, and UDP. It returns data to the receiver in XML format.

What are constructors?

Special methods of the class which are used to assign initial values to the data members of the class.

What does it mean to 'step into'?

Step into notifies the debugger to enter INTO a specific function/method. Can step into by click Debug> Step Into(F11)

What does it mean to 'step over'?

Step over notifies the debugger to NOT enter a specific function/method. Can step over by clicking Debug > Step Over(F10)

What are some examples of reference data types?

String, Object.

What class do all classes in C# inherit from?

System.Object

What is the namespace for serialization?

System.Runtime.Serialization;

What is a Uri?

The 'endpoint'... URI stands for Uniform Resource Identifier by creating a new instance of the URI class you can point it to a resource(typically a url) which can then be used when making a webrequest(side note uses 'System' namespace) Uri siteUri = new Uri("http://www.contoso.com/"); WebRequest wr = WebRequest.Create(siteUri);

What are Gang of Four design patterns?

The Gang of Four(GoF) design patterns are 23 distinct solutions to general problems that software developers face during software development

What is inheritance?

The ability to create a class that inherits attributes and behaviors from an existing class

What is managed code?

The code which is developed in the .NET framework and is handled directly by the CLR

What is a child class?

The derived class. A class which inherits fields and methods from another class

What is the default access specifier in C#?

The general rule of thumb is that all members are given the most restrictive access specifier they can have by default. For example, class fields are by default private.

What does it mean for a programming language to be object-oriented?

The language handles programming problems through the use of classes and objects, with objects being bundles of data and properties which act on that data

What is abstraction?

The process in which only the most essential details are shown to the user Real life example: You can drive a car without knowing how all the parts within it work (engine/wiring). Rather, you just need to know how to operate the most essential parts (gas pedal, brakes, blinker, etc.)

What is encapsulation?

The process of enclosing one or more items within a 'package' and hiding the data in a class from other classes (data-hiding)

What is serialization?

The process of turning an object in memory into a stream of bytes so you can do stuff like storing it or sending it over a network

What is the software development life cycle (SDLC)?

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 -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

Why use a static class?

The sole purpose of the class is to provide blueprints of its inherited classes.

What is 'step out'

The step out (shift + f11) feature in debugger mode allows you to 'step out' of the function that you may have 'stepped into' This command executes the rest of the current function and breaks when the function return is completed.

What is Common Language Runtime (CLR)?

The virtual machine of the .NET framework which .NET programs are run on.

What does the volatile keyword mean?

The volatile keyword informs the compiler that the designated variable can have its variable changed by another thread during run time

Distinguish the difference between waterfall and agile methodology

The waterfall methodology ensures that the software is completely developed before being deployed. In the agile framework parts and components of a given product are completed during sprints and are deployed. This allows immediate feedback from end users and any bugs/defects can be addressed in a following sprint

What are nullable types?

They allow you to assign null to a value type variable.

What is a structure?

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 inheritance, but they can implement interfaces They can contain constructors, constants, fields, and methods and struct objects can be created without the use of the 'new' keyword

What are access specifiers in C#?

They are used to control security of a class, method, or variable and help achieve encapsulation

How is abstraction achieved?

Through the use of abstract classes

How is encapsulation achieved?

Through the use of access specifiers. In particular, you declare all the fields of a class private and use properties (accessor methods) to get and set the values of these fields

What is the 'is' keyword used for?

To check if a variable is of a given type

How do you create a database connection?

Use the System.Data.SqlClient namespace Specify the database you're connecting to in the sqlconnection string Create the query command you want to execute Execute that command and get the returned query

What is the 'base' keyword used for?

Use to access members of a base class from within a derived class. For example, to access a base class method that has been overridden by a derived class method

What does the readonly keyword do?

Used to create a variable whose value cannot be edited except at run time (within the constructor)

What is 'var' used for?

Used to declare variables without giving an explicit type. 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 does the ref keyword do?

Used to indicate that a value is passed by reference You can use it to pass an argument to a method by reference, or to return a value to a caller by reference It requires that the variable being passed is initialized before being passed Note: The ref keyword can be used on both reference types and value types.

What does 'volatile' mean?

Used to inform the JIT compiler that the value of the variable might be changed by multiple threads

What are the two types of variables in C#?

Value (e.g., int, float, char, byte) Reference (e.g., String, Object)

What is the difference between value type and reference type?

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. 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 the differences between virtual methods and abstract methods?

Virtual methods have an implementation and provide derived classes the option of overriding it Abstract methods have no implementation and derived classes are forced to override the method

What is Web Services Description Language (WSDL)?

WSDL documents describe a web service and is written in XML.

What does the virtual keyword do?

When used with a base class method, it allows the method to be overridden in a derived class

Why would you want to use an abstract class (or method)?

When you would like to force derived classes to implement methods, usually unique to them

What are the two extensions in unit testing?

XUnit NUnit

Are abstract methods and properties inherently virtual?

Yes

Can you use partial methods?

Yes

Is C# statically typed? If so, what does that mean?

Yes, and this means that it has a type system that is checked at compile time. The workaround is to use the 'dynamic' keyword

Is C# case sensitive?

Yes, this includes variable and method names

How do you debug in Visual Studio?

You can use the Debug functionality already provided by the IDE. When you run your application with the debugger enabled you are able to see into your code as it is executing and insert breakpoints as needed.

How can you unit test in visual studio?

You can use the Visual Studio provided unit tester by declaring the namespace, specifying [TestClass] & [TestMethod] attributes when testing classes and methods respectively using Microsoft.VisualStudio.TestTools.UnitTesting;

What is the syntax for class declaration?

[Access modifier] [Class keyword] [Identifier (i.e. class name)] 'public class MyClass'

What is the syntax for method declaration?

[access modifier] [return type] [method name] [parameters] public void MyMethod(int parameter1, string parameter2)

What is the syntax for variable declaration?

[data type] [variable name] [assignment operator] [value] int i = 1;

Example of passing a reference type argument by ref

class Product { public Product(string name, int newID) { ItemName = name; ItemID = newID; } private static void ChangeByReference(ref Product itemRef) { // Change the address that is stored in the itemRef parameter. itemRef = new Product("Stapler", 99999); } private static void ModifyProductsByReference() { Product item = new Product("Fasteners", 54321); System.Console.WriteLine("Name: {0}, ID: {1}\n", item.ItemName, item.ItemID); ChangeByReference(ref item); System.Console.WriteLine("Name: {0}, ID: {1}\n", item.ItemName, item.ItemID); } // Output: Name: Fasteners, ID: 54321 Name: Stapler, ID: 99999

What is typecasting?

converting the value of one data type to another.

Example of enum

enum Days { Sun, Mon, Tue, Wed, Thu, Fri, Sat }; Sun would hold the value 0

What are the different value types that can hold decimal values?

float, double, Decimal, Decimal has the greatest precision

What are some examples of value data types?

int, float, char, byte, decimal

Example unit test

namespace BankTests { [TestClass] public class BankAccountTests { [TestMethod] public void TestMethod1(){} } }

Example of inheritance

public class DerivedClass : BaseClass { //Derived class properties and methods }

Action example

public delegate void Print(int val); static void ConsolePrint(int i) { Console.WriteLine(i); } static void Main(string[] args) { Print prnt = ConsolePrint; Prnt(10); }

Example of method overriding

public override double Area() { // Derived implementation }

How do you create a lambda expression in C#?

s => s.Age > 12 && s.Age < 20 where s is the parameter, => is the lambda operator and the rest is the body.

What is the syntax for extending a class in C#?

separated by : derivedclassname:baseclassname

What are collections?

specialized classes that hold many values or objects in a specific series. e.g. ArrayList, HashTable, SortedList, Stack, Queue

Predicate example

static bool IsUpperCase(string str) { return str.Equals(str.ToUpper()); } static void Main(string[] args) { Predicate<string> isUpper = IsUpperCase; bool result = isUpper("hello world!!"); Console.WriteLine(result); }

Example of a 'func'

static int Sum(int x, int y) { return x + y; } static void Main(string[] args) { Func<int,int, int> add = Sum; int result = add(10, 10); Console.WriteLine(result); } }

Multi-Threading code snippet

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++) { Console.Write("x"); Console.ReadLine(); } } static void WriteY() { for (int i = 0; i < 10000000; i++) { Console.Write("y"); Thread.Sleep(1000); // let the thread `sleep` for one seconds before running. } } }

Example of passing a value type argument by ref

void Method(ref int refArgument) { refArgument = refArgument + 44; } int number = 1; Console.WriteLine(number); Method(ref number); Console.WriteLine(number); // Output: 1 45

What is Simple Object Access Protocol (SOAP)?

An XML-based messaging protocol for exchanging information among computers

What are accessor methods?

Commonly known as getters and setters, they are methods used to access private field values

What is a field?

Fields are ordinary member variables of a class

What is the benefit of inheritance?

It provides for code reusability

Can a static method/class be abstract?

No, because static methods/classes cannot be inherited or overridden

What are the differences between SOAP and REST

SOAP requires XML formatting while REST supports multiple data formats such as HTML, JSON, XML, and plain text

What is a derived class?

Same as a child class: a class which inherits another class

What is a parent class?

A class which inherits

What is a base class?

A class which is inherited

What is Just-In-time (JIT)?

A compiler which is used is used as a part of the runtime execution environment. It turns CLR into machine code.

What is the common type system?

A component of the CLR which standardizes data types across all .NET supported languages

What is a private constructor?

A constructor of a class that has been declared as private. It prohibits the ability of creating an instance of said class for any other code outside of the class itself

What is a static constructor?

A constructor used to initialize static data members of a class

What is a solution in visual studio?

A container of one or more related classes

What is .NET core?

A cross platform version of the .NET framework. It has limited capability compared to the .NET framework

What is a tuple?

A data structure that contains a sequence of elements of different data types.

What is a 'dynamic' type?

A data type that escapes type checking at compile time, and instead resolves it at runtime

What is the difference between var and dynamic?

var designates the type at compile time whereas dynamic evaluates the type at run time

What are some examples of unmanaged code?

Code that uses pointers Any code that is not supported by the CLR runtime environment

What is a jagged array?

An array which contain arrays

Can an interface extend another interface in C#?

yes


Related study sets

ISDS Database Exam Prep - SQL and DB Design

View Set

Political beliefs and behaviors test

View Set

Ch 104 client centered experience

View Set

Chemical Bonding and Compounds folder

View Set