Introduction

These days whenever we go for an interview, we are often required to take some sort of coding test. This is to give an idea to the employer on how we approach a problem and try to solve it. Even if we do not finish this coding test in the allocated time, we will be analyzed on the design and approach we used. This will help the employer to decide if they want to hire us or not. However, in addition to the design pattern and libraries we use, the syntax and basic code layout is also particularly important to make a good impression. Today, I will list some of the cool tips to make your C# code look better and more professional and impress in a coding test.

Cool things to apply in your C# coding test to impress

Always create interface before classes

This will show that you understand the importance of interface and class relationships and unit testing in your code.

Define properties using the new => syntax

This is the latest way to allocate values to properties and will show that you are updated on the latest code syntax improvements.

Use multiple return values if needed (new tuples).

This will show you understand and use the latest features of the coding language.

Use class inheritance where needed.

This will show you understand the basic principles of object-oriented programming and apply them.

Use dependency injection in classes and when creating them use the NEW keyword in the parameters as below.

This is a very important point as use of the new keyword is a direct violation of the Dependency Inversion principle which is a core component of the SOLID principles. e.g.:

class Customer: IDiscount, IDatabase {  
    private Ilogger obj;  
    public Customer(ILogger i) {  
        obj = i;  
    }  
}  
IDatabase i = new Customer(new EmailLogger());  

Also, mention that a dependency injection framework can be used e.g. Ninject, Castle Windsor, Unity etc.

#programming-c #csharp

Cool Tips For A C# Coding Test
1.35 GEEK