Blog for Junior Developers C#/.NET

Monday, June 17, 2024

If you want to become a .NET developer, you definitely need to attend at least a few job interviews. Such interviews may look a little different in each company, but you will always have a lot of technical questions during such an interview. In the upcoming articles, I will present you 100 interview questions and answers for junior C# programmers. We will divide this series into 10 articles with 10 questions and answers for each article.

100-interview-questions-and-answers-for-junior-developers-csharp-dotnet-part-1-10.jpg

I will try to answer all questions as briefly and precisely as possible. Some answers could be developed further, but in such cases I will also refer you to appropriate sources.


1) What is C#?


C# is a language from the .NET family originally developed by Microsoft. It was created on the basis of C++ and C languages. Initially, C# was very similar to Java, but over time, the similarity becomes less and less. C# is a popular, high-level programming language, it is a general-purpose language, which means that you can write various applications in it, i.e. web, desktop, mobile applications and even games. A program written in C# is compiled into Intermediate Language (IL), i.e. intermediate code executed in the .NET runtime.


2) What is .NET Framework?


.NET Framework is a programming platform developed by Microsoft, released in 2002. It includes the CLR, i.e. the runtime environment on which written programs run, as well as class libraries that implement typical functionalities used in .NET applications. The mentioned libraries are a set of functionalities and methods that facilitate the work of programmers. Thanks to which you can use ready-made implementations. The .NET platform's tasks include managing application code, memory, and security. Programs for the .NET platform can be written in various languages, such as C#, F#, Delphi 8, Visual Basic .NET, COBOL, Eiffel, Fortran, Lisp, Perl.


3) What are the differences between .NET, .NET Core, and .NET Framework?


The .NET Framework was created in 2002 and is a programming platform on which you can only create Windows applications. However, .NET Core is a kind of successor, it was released in 2016. It is open source software thanks to which you can create and run your applications written in C#, among others, on Windows, Linux and macOS platforms. In addition, the libraries and runtime environment have been optimized in .NET Core, so applications created in .NET Core are even more efficient. The .NET corea source code is open and available on github. In 2020, .NET 5 was released, which can be said to have combined the .NET Framework with .NET Core. Now a new version is to be released every year, i.e. .NET 6 this year, .NET 7 next year, etc. This will certainly bring some order, as different versions of the .NET Framework and .NET Core have caused some confusion in recent years. years.


4) What are namespaces in C#?


Thanks to namespace, the namespace in C# can better organize the code in C# and introduce code separation. You can think of namespaces as a box that consists of other namespaces, classes, methods, properties, etc. To define a namespace, we use the namespace keyword: Example:

namespace App
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
        }
    }
}

So our Program class is available inside the App namespace. However, if we would like to use this class in another namespace, we must provide the full name of the class along with the namespace, or add a reference using the using keyword.

using app;


5) What are the comment types in C#?


In C# we have 3 types of comments. These are single line comments:

//Single line comments

Multi-line comments:

/*
Multi line comments
…
Multi line comments
*/

And comments on the documentation

/// <summary>
/// Method return sum of 2 parameters
/// </summary>
/// <param name="number1">Number 1</param>
/// <param name="number2">Number 2</param>
/// <returns>Sum</returns>
public int Sum(int number1, int number2)
{
    return 1;
}

They can be created into XML documentation and are also displayed as tooltips in IntelliSense.


6) What are the types of loops in C#?


There are 4 types of loops in C#. These are for, while, do while and foreach loops.


for (int i = 0; i < length; i++)
{

}

while (true)
{

}

do
{

} while (true);

foreach (var item in collection)
{

}


7) What is the difference between a while loop and a do while loop?


The basic difference between a while loop and a do while loop is that the do while loop will always execute at least once, because the logic is performed first and only then the condition is checked. However, the while loop may not be executed even once if the condition is not met at the beginning.

while (1 < 0)
{
    Console.WriteLine("x");
}

//Wynik:

do
{
    Console.WriteLine("x");
} while (1 < 0);

//Wynik: "x"


8) What is the difference between the continue and break keywords?


We can use both keywords inside the loop iteration. If continue is executed in an iteration, the current iteration will be skipped and we will move on to the next one. In the case of break, not only the current iteration will be terminated, but the entire loop will be terminated.

for (int i = 0; i < 10; i++)
{
    if (i == 5)
        continue;

    Console.WriteLine(i);
}

//Wynik: 0, 1, 2, 3, 4, 6, 7, 8, 9

for (int i = 0; i < 10; i++)
{
    if (i == 5)
        break;

    Console.WriteLine(i);
}

//Wynik: 0, 1, 2, 3, 4


9) What is the difference between a class and an object?


A class is a definition of an object, it describes the states and behaviors of the object. An object is an instance of a class, its behavior is defined in the class. If we create a new object, i.e. an instance of a class, we create a specific instance whose behaviors, i.e. methods and states, i.e. properties and fields, have been defined in the class. So a class is a template based on which we can create new objects. Once we have a class, we can create many objects based on it.

public class Student
{
    public string Name { get; set; }

    public void DisplayName()
    {
        Console.WriteLine(Name);
    }
}

public class Program
{
    static void Main(string[] args)
    {
        var student = new Student();
        student.Name = "Jan";
        student.DisplayName();
    }
}


10) What is the difference between declaration and initialization?


The declaration itself is only about creating a place in memory where the value of a given variable will be stored.

int a;

Initialization, on the other hand, means assigning a value to a previously declared variable, for example.

a = 1;

There is nothing stopping you from making a declaration and initialization at the same time.

int b = 2;


TERMINATION


That's all the questions in this article. We will analyze the next ones in the next article. If you like this material, be sure to join my community - free registration, where you will also have access to additional materials.

That's all for today, see you in the next article.

Author of the article:
Kazimierz Szpin

KAZIMIERZ SZPIN
Software Developer C#/.NET, Freelancer. Specializes in ASP.NET Core, ASP.NET MVC, ASP.NET Web API, Blazor, WPF and Windows Forms.
Author of the blog CodeWithKazik.com

Previous article - Ref vs Out Examples in C#
Next article - 100 Interview Questions (and Answers!) for Junior Developers C#/.NET (Part 2/10)
Dodaj komentarz

Search engine

© Copyright 2024 CodeWithKazik.com. All rights reserved. Privacy policy.
Design by Code With Kazik