Preparing for Exam 70-483: Programming in C#

During preparation for exam 70-483, I found lots of websites containing links to various manuals that helped me a lot. But what really helped me was the memo notes I composed for myself and which I’d like to share in this article. I do not target to provide a detailed description of C#, I just want to refresh your memory and to highlight certain aspects of C#. If you are not familiar with some aspects, it means you have gaps in your knowledge that should be eliminated.

Also, I will not cover testing issues, but the tricks, nuances listed below may help you.

Let’s start with simple things which, nevertheless, are often neglected, but are widely used in tests:

To declare an int variable and assign the 0 value to it at once, we can:

var myInt=0; or int myInt=0;

To declare an int variable and assign a default value to it at once, we can:

int myInt = new int();

Explicit and Implicit Typing

Use the implicit typing for:

  • anonymous testing –  var anonymousType = new { Name = «Alex» }; ar anonymousType = new { Name = «Alex» };
  • getting result from the LINQ query – var queryExpression = from c in customers where c.Name == «Andrey» select c;
  • using complex generic types – var searchList = new Dictionary();
  • implicit typing is possible only for local variables.

Boxing/Unboxing

Boxing is the conversion of a value type into a reference type.

Unboxing is vice versa, the conversion of a reference type into  a value type. Unboxing requires Cast.

Boxing/Unboxing copies the variable value.

In terms of calculation speed, boxing is an operation taking up a considerably large amount of processor resources.

A simple example:

An interesting example of an error:

Another example:

The ?? operator is called a null-coalescing operator. It returns the left value, if it does not equal null, otherwise – the right value. An example:

The ? operator is called a conditional operator. It returns one of two values basing on the Boolean expression. If an expression equals true, the first value is returned; otherwise, the second value is returned. Here are 2 similar codes, for example:

LINQ

Any object that implements the IEnumerable or IQueryable interface can be queried using LINQ.We can use either

We can use either orderby…descending, or OrderByDescending.orderby h.State, h.City – here

orderby h.State, h.City – here orderby is written in one word, however, group h by h.State is written separately (there is also a variant of the capitalized GroupBy)Predicate is a condition that characterizes a subject. For example:

Predicate is a condition that characterizes a subject. For example:

There are 2 variants of writing LINQ (method syntax/method and query syntax/query):

Simple LINQ methods:

There is an interesting option of using where instead of && several times. For example:

Functions can be used as a filter. For example:

If we need to select several values, we need to use new { }

We can even set aliases:

LINQ deferred execution – a query is executed till the element is called. For example:

The assembly version comprises of four parts: Major, Minor, Build, and Revision.

To install the GAC (Global Assembly Cache) assembly, the Global Assembly Cache tool (Gacutil.exe) is required. You need to enter the following line into the command line: gacutil –i.

But the assembly must be signed with a strong name key with help of SN. An example of key creation: «C:\GACKey\GACkey.snk» sn –k.

Strong name assembly consists of 5 parts: Friendly Name, Version, Culture, Public Key Token, and Processor Architecture.When you sign your assemblies, store your key in a safe place, and give developers only an open part of the key – it will allow them to use assemblies without a full signature.

When you sign your assemblies, store your key in a safe place, and give developers only an open part of the key – it will allow them to use assemblies without a full signature.You can highlight the open part of the key with the following command:

You can highlight the open part of the key with the following command:Sn.exe –p «key.snk» «open key.snk»

Sn.exe –p «key.snk» «open key.snk»Since the assembly version is important at the moment when the runtime is trying to find the assembly, you can publish various versions of the same assembly in GAC and evade problems with normal

Since the assembly version is important at the moment when the runtime is trying to find the assembly, you can publish various versions of the same assembly in GAC and evade problems with normal ddls.

It is called a side-by-side hosting at which many versions of the same assembly are hosted on the same computer (as from .NET 4).

Shallow copy – a trap when copying arrays

When copying arrays of the reference type, a pointer to the value can be copied instead of the value itself. An example:

Closures

This result is conditioned by two reasons:

  1. During closures, variables, not variable values, are captured.
  2. The provided code fragment contains one instance of the i variable, that is modified at each loop iteration, instead of creation of a new instance at each iteration.

We can easily fix this situation:

Do you use compiler directives?Here are few examples of directives:

#region and #endregion – limit a certain part of code and allow rolling/unrolling.

#define and #undef – define true or false for certain values.

#error – generates an error

An example of a condition which will execute one code fragment in the Debug mode, and another fragment in another case:

#if DEBUG
#elif
#endif

What is PCL? Portable Component Library is a dll but with the cross-platform options. That is, you can create PCL and set platforms in which it will be used (e.g. WP8, WinRT, Xamarin… ). In fact, the addition of each platform limits the assembly capabilities.

PDB is an acronym for the Program database file.

PDB contains debugging data and data about the project state that allow the execution of sequential compilation of debugging function of the program.
Anyone who has access to the ddl/exe file can easily perform reverse engineering to generate the source code with PDB or without it using such tools, as a reflector. So, provision or non-provision of PDB does not have any influence on the code security.

Implicit and Explicit implementation

Suppose, that we have 2 interfaces with a similar method:

We create a class that is inherited from two interfaces and declare the interfaceMethod in it:

We used the Implicit interface implementation. And if we specify the interface name, it will turn into the explicit implementation:

In the information science, reflection means a process during which a program can track and modify its own structure and behavior during execution. An example:

During reflection, the assembly can be loaded in several ways:

  • Assembly.LoadFrom() can make redirection to other similar assembly.
  • Assembly.LoadFile() loads the assembly from a file.
  • Assembly.Load() loads the assembly basing on its full name specified.

The difference between the Convert and Parse methods is that Parse accepts row as an input value, while Convers can accept other data types.

The difference between Parse/TryParse and Convert is that Convert can accept null values and does not throw ArgumentNullException.

To provide positive and negative infinity, C# has two special constants: System.Double.NegativeInfinity and System.Double.PositiveInfinity.NegativeInfinity — the value of this constant is the result of

NegativeInfinity — the value of this constant is the result of division of a negative number by null. Also, this constant is returned, if the operation result is less than the minimum value (MinValue).PositiveInfinity is the result of

PositiveInfinity is the result of division of a positive number by 0. The constant is returned, if the value is greater than MaxValue.Infinity includes both, NegativeInfinity and PositiveInfinity,

Infinity includes both, NegativeInfinity and PositiveInfinity,The unchecked keyword is used to suppress the overflow checking during execution of arithmetic operations and transformation of integer data. If the unchecked environment is deleted, the compilation error occurs. 2 examples:

The unchecked keyword is used to suppress the overflow checking during execution of arithmetic operations and transformation of integer data. If the unchecked environment is deleted, the compilation error occurs. 2 examples:

By default, C# does not throw exception, if during the narrowing transformation, the error with the int and float types occurs.

To make this exception occur, we can use the checked keyword. An example:

Also, we can put the check-mark in the project properties to throw an exception during overflow/underflow.

Formatting

Rethrow exception

The error stack is cleared every time when the error is thrown.

It is recommended to use just throw, since in this case, information about initial error is saved.

Optionally, we can create our own error – custom exception.

After that, we can throw the error:

It is not recommended to inherit from System.ApplicationException. Notionally, it was supposed that all C# runtime errors must be inherited from System.Exception, and all custom exceptions – from System.ApplicationException. But in practice, the System.ApplicationException was not used at all.In the

In the try/catch/finally block, finally is always executed. Except the case of calling Environment.FailFast(String) or FailFast(String, Exception) in the code. They interrupt the current process in the cases of any critical damages of the application work, and the program execution will be interrupted, and finally will not be executed.

CodeDOM is a set of classes that allow generating code.

The System.CodeDom.CodeCompileUnit is a top-level class, a container for all objects in the generated code.

The System.CodeDom.CodeDOMProvider class generates the file class in C#, VB or JScript.

Similar to classes, structs can have methods, properties, constructors, etc.

Unlike classes, structs cannot contain destructors (in fact, destructors are the Finalize methods of the ~CalssName that allow destroying an object).

You cannot declare an empty constructor for a struct. Also, structs cannot have inheritance hierarchies (for the purpose of memory saving).

Also, structs cannot have inheritance hierarchies (for the purpose of memory saving). In C#, structs are implicitly sealed. It means that a struct cannot be inherited from.

Structures – value data type = stored in stack.

Classes – value data type = stored in heap.

In C#, structs and enumerations are of the value data type .Structs, in their turn, are divided into the following subcategories: numeric type (integral types, floating-point types, 128-bit decimals), boolean type and user structs.

Structs, in their turn, are divided into the following subcategories: numeric type (integral types, floating-point types, 128-bit decimals), boolean type and user structs.

Enumerations are sets of types declared with the enum keyword.

The value type has two limitations:

  • You cannot inherit from the value type
  • Value type cannot accept null value
The Interlocked class provides atomic operations for variables that are available fro several threads (Decrement(Int), Increment(Int), Add(Int, Int) operations). The variable value will be changed simultaneously for all threads.The Compare Exchange method compares two values for equality. If they are equal, it replaces one the values.

The Compare Exchange method compares two values for equality. If they are equal, it replaces one the values.

The Exchange method sets variable by a specified value, similar to the atomic operation, returns the initial values. An example:

Parameters passed to functions

Normally, the function is called in the following way: CalculateBMI(123, 64);If we don’t remember the order, we can call the function by specifying names:

If we don’t remember the order, we can call the function by specifying names:

First, we need to specify a parameter by order, and then – by name:

You cannot specify the first parameter by name, and then – by order (leads to an error)

We can specify default values for parameters and then call the function without indicating these parameters:

Using StringWriter and StringReader for writing and reading strings

Comparison of Generics and ArrayList

Regex (regular expressions)

An example of IsMatch:

Matches – searches for all entries of a regular expression in the input string and returns all the matches:

Match works similar to Matches, but searches for the first match only.

Split divides the input string into the substring array in the positions defined by correspondence of the regular expression.

string input = «plum-pear»;

string pattern = “(-)”;

Replace – replaces all strings in the input string that correspond to the template of the regular expression with the specified change string.

^ — start of the string, $ — end of the string. – any symbol

* — repetitions of the previous 0 or several times

+ — repetition of the previous 1 or several times

? – repetition of the previous 0 or 1 time

[abc] – any of a, b or c symbols, [^abc] – any symbol except these, [a-z] – symbols from…to, [^a-z] – symbols except from…to

{n} – match of n repetitions, {n,} – match from n to infinity, {n,m} – match from n to m times,

\d – a number, \D – not a number, \s – space, tab etc, \S – not space

Few Tricks

In spite of prohibition of exam info disclosure, you can easily find dumps (question information leaks) on the web. Are they worth of using? Do they really help? Taking into account blog posts, many people do use dumps. IMO, it is better not to stick to them. Firstly, they contain many mistakes. Also, do not forget that questions change from time to time. Can you cheat in the exam? Well, you could be lucky enough with the questions, but we are interested in knowledge not in a paper, aren’t we?

A legal way to find question examples is to look through the questions in the books, like “MCSD Certification Toolkit Exam 70-483 Programming in C#” and “Wouter de Kort Programming in C# Exam Ref 70-483”. I would recommend you to pay attention to the very subject of the question subject, not the options for an answer. In this way, you will learn nuances and work on unknown aspects.

As for video tutorial, I recommend a course at MVA (the portal is absolutely free) – www.microsoftvirtualacademy.com/training-courses/developer-training-with-programming-in-c

There is also an interesting training game at www.codehunt.com. It will not prepare you for the test, but may be interesting as a warm-up.

The best legal way to improve your knowledge and grade is to look though and think over all questions after passing the test.

That’s it. I wish everyone good grades and great knowledge in C#!

Alexey Sommer

Alexey Sommer

Alexey Sommer is mostly working on UWP development. He has the MVP award in the Windows Development category, as well as MCP and MCSD certificates.
Alexey Sommer

Latest posts by Alexey Sommer (see all)

Alexey Sommer

Alexey Sommer is mostly working on UWP development. He has the MVP award in the Windows Development category, as well as MCP and MCSD certificates.