Fragen und Antworten zu C#-Interviews

PHPz
Freigeben: 2024-09-03 15:35:37
Original
273 Leute haben es durchsucht

It is type-safe and a managed language. Many operating systems use it, so one must understand this language strongly. It is highly in demand, and due to its versatility, it can support many operating systems.

You have finally found your dream job in C# but are wondering how to crack the 2023 C# Interview and what the probable C# Interview Questions could be. Every interview is different, and the job scopei is different too. Keeping this in mind, we have designed the most common C# Interview Questions and Answers to help you get success in your interview.

Part 1 – C# Interview Questions (Basic)

This first part covers basic C# Interview Questions and answers.

Q1. What is Managed and Unmanaged code?

Answer:

Managed code is executed on the .Net platform. It uses CLR (Common Language Runtime) for all application code based on that platform. The application, when executed, is responsible for managing factors such as memory, security, and performance. These are among the key C# interview questions that one might expect in an interview.

Q2. What are the different types of classes in C#? Explain each class in short.

Answer:

There are four types of classes in C#. They are as follows:

1) Static class: This class does not allow inheritance. The members within this class are static and identified by the keyword “static”.

2) Abstract class: This class is denoted by the keyword abstract. The objects of these classes cannot be instantiated. This class can only be inherited and must contain at least one method.

3) Sealed class: This class cannot be inherited. To access, an object of this class should be created. It is made using the keyword Sealed.

4) Partial class: By using the “partial” keyword, a class can be designated as “partial,” which permits its members to be divided or shared among multiple .cs files.

Let’s move on to the following C# Interview Questions.

Q3. What are C# I/O classes?

Answer:

C# uses the System.IO namespace, which consists of classes that perform various operations like create, delete, open, close, etc. The commonly used I/O classes are:

  • File: Helps in performing multiple operations on a file. It helps in the creation and manipulation of files.
  • StreamWriter: For writing characters to a stream.
  • StreamReader: Used for reading characters from a stream.
  • StringWriter: Used for writing a string to a buffer.
  • StringReader: Used for reading a line from a pad.
  • Path: Used when a user wants to perform operations related to the course.

Q4. Explain StreamReader/ StreamWriter class.

Answer:

Both these classes belong to namespace System.IO. StreamReader class includes members like: close(), read(), Readline(). StreamWrier class includes members like close(), write(), writeline().

class Program1
{
using(StreamReader sr = new StreamReader("C:\ReadMe.txt")
{
//----------------code to read-------------------//
}
using(StreamWriter sw = new StreamWriter("C:\ReadMe.txt"))
{
//-------------code to write-------------------//
}
}
Nach dem Login kopieren

Q5. Explain the concept of Boxing and Unboxing?

Answer:

Boxing is a value is converted to a reference type.

Example:

int value -= 20;
//-----------Boxing------------//
Object boxValue= value;
Nach dem Login kopieren

Here boxValue references ‘value’.
Unboxing is the process of explicitly converting from a reference type back to a value type.

Example:

//————UnBoxing——————//
int UnBoxing = int (boxedValue);
Nach dem Login kopieren

Unboxing references back to original value.

Part 2 – C# Interview Questions (Advanced)

Let us now have a look at the advanced C# Interview Questions.

Q6. What are Regular Expressions? Write a regex to find a string using?

Answer:

Regular expressions patterns to templates to match a given set of input. These patterns may contain operators, character literals, symbols, etc. Developers commonly use regular expressions (regex) to parse strings or replace specific characters within them. Using regex, developers can search for any pattern in a given input file or string, making it a powerful tool for processing text-based data.
Example:

static void Main(string[] args)
{
string[] lang = { "C#", "Python", "Java" };
foreach(string s in lang)
{
if(System.Text.RegularExpressions.Regex.IsMatch(s,"Python"))
{
Console.WriteLine("Match found");
}
}
}
Nach dem Login kopieren

This code example utilizes Python to search for a specific language within an array. This method allows developers to use regular expressions to locate specific matches within the input.

Q7. What are the different types of Delegates?

Answer:

The different types of delegates are:

  • Einzelner Delegat: Wenn ein Delegat eine einzelne Methode aufruft, handelt es sich um einen einzelnen Delegaten.
    • Multicast-Delegierter: Wenn ein Delegat mehrere Methoden aufruft, handelt es sich um einen Multicast-Delegierten. Ein Benutzer kann die Operatoren + und – verwenden, um sich anzumelden und abzumelden.
    • Generischer Delegat: Es gibt drei Arten von generischen Delegaten. Es handelt sich um Aktionen, Funktionen und Prädikate.

F8.  Was ist ein Lambda-Ausdruck in C#?

Antwort: Ein Lambda-Ausdruck ist eine prägnante Möglichkeit, anonyme Methoden in C# zu definieren. Es wird häufig in LINQ-Abfragen und zum Definieren von Delegaten oder Ereignishandlern verwendet. Lambda-Ausdrücke machen den Code lesbarer und ausdrucksvoller.

F9. Was sind Delegierte in C#?

Antwort: Ein Delegat ist ein Typ, der Verweise auf Methoden mit einer bestimmten Parameterliste und einem bestimmten Rückgabetyp darstellt. Delegaten werden zum Definieren von Rückrufmethoden und zum Implementieren der Ereignisbehandlung verwendet und sind ein grundlegender Bestandteil von C#-Ereignissen und Rückrufen.

F10. Erklären Sie das Konzept des Boxens und Unboxings in C#.

Antwort: Beim Boxen handelt es sich um den Prozess der Konvertierung eines Werttyps in einen Referenztyp, und beim Unboxing handelt es sich um den umgekehrten Prozess der Konvertierung eines geboxten Werts zurück in einen Werttyp. Das Ein- und Auspacken kann Auswirkungen auf die Leistung haben und sollte daher mit Bedacht eingesetzt werden.

Das obige ist der detaillierte Inhalt vonFragen und Antworten zu C#-Interviews. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Verwandte Etiketten:
Quelle:php
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!