Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
Common Asked C# Interview Questions for Experienced (5+ years)
2.1.
1. Explain C# in just two statements.
2.2.
2. Can you write a code on Boxing and Unboxing in C#? 
2.3.
3. In C#, What is the difference between a struct and a class?
2.4.
4. What exactly is cohesion?
2.5.
5. Why are strings immutable in C#?
2.6.
6. What are the distinctions between Array and Array List in C#?
2.7.
7. What exactly are Jagged Arrays?
2.8.
8. Define constructor in the easiest language constructors.
2.9.
9. What exactly is the distinction between public, static, and void?
2.10.
10. In C#, What are partial classes?
2.11.
11. What exactly are Indexers in C#?
2.12.
12. What is the difference between Custom Control and User Control?
2.13.
13. What is the distinction between System.String and System.Text.StringBuilder?
2.14.
14. What exactly is reflection in C#?
2.15.
15. Why is the "finally" block used in C#?
2.16.
16. In C#, what is the difference between the "out" and "ref" parameters?
2.17.
17. What is the purpose of 'Data Type Conversion' in C#?
2.18.
18. What is the GAC, and where can I find it?
2.19.
19. What is a circular reference in C#?
2.20.
20. What exactly is an Object Pool in.Net? What does it imply?
2.21.
21. Explain Accessibility Modifiers in C#.
2.22.
22. What exactly are Anonymous Types in C#?
2.23.
23. What is the distinction between the methods Finalize() and Dispose()?
2.24.
24. What exactly are Custom Exceptions?
2.25.
25. What exactly are delegates?
2.26.
26. Write a program in C# to find if a positive integer is prime or not?
2.27.
27. Write a program in C# to find the substring from a given string?
2.28.
28. Write a program in C#  to reverse the order of the given words?
2.29.
29. What is Console application?
2.30.
30. Is C# code is managed or unmanaged code?
3.
Frequently Asked Questions
3.1.
What are the most important things that you must do in an interview?
3.2.
What are all the C# important topics for an experienced interview?
3.3.
What is Garbage collection in c#?
4.
Conclusion
Last Updated: Mar 27, 2024
Medium

C# interview questions for 5 years Experience

Create a resume that lands you SDE interviews at MAANG
Speaker
Anubhav Sinha
SDE-2 @
12 Jun, 2024 @ 01:30 PM

Introduction

Well, if you have worked with C# for almost 5 years, then you must be familiar with all the basics and intermediaries of the language. And if you are looking for a job, then coding ninjas got you covered. In this blog, we are going to discuss 30 C# interview questions for 5 years experience that have a high chance of being asked in your upcoming interview.

Common Asked C# Interview Questions for Experienced (5+ years)

1. Explain C# in just two statements.

Ans: C# is a general-purpose programming language that includes object-oriented, functional, and component-oriented programming. It is used to develop a wide range of programs and applications, including mobile apps, desktop apps, cloud-based services, websites, enterprise software, and games.

 

2. Can you write a code on Boxing and Unboxing in C#? 

Ans: The methods of boxing and unboxing are used for type conversions. Boxing is converting from a value type to a reference type. Boxing is an implicit conversion. Here's an example of C# boxing.

// Boxing  
int num1 = 1;  
Object obj = num1;  
Console.WriteLine(num1);  
Console.WriteLine(obj); 


Unboxing is the process of converting from a reference type to a value type. Here's a C# example of unboxing.

// Unboxing  
Object obj2 = 1;  
int num2 = (int)obj;  
Console.WriteLine(num2);  
Console.WriteLine(obj);

 

3. In C#, What is the difference between a struct and a class?

Ans: Class and struct are both user-defined data types, but they differ significantly:


 

4. What exactly is cohesion?

Ans: In OOPS, we write code in modules. Each module is responsible for a specific task. Cohesion measures how closely a module's responsibilities are related.

Greater cohesion is always preferable. Benefits of increased cohesion include:

  • Module maintenance is improved.
  • Improve reusability.

 

5. Why are strings immutable in C#?

Ans: String values are immutable, which means they cannot be changed once they have been created. Any change to a string value creates a new string instance, resulting in inefficient memory use and extraneous garbage collection. The System is malleable. When string values change, the Text.StringBuilder class should be used.

 

6. What are the distinctions between Array and Array List in C#?

Ans: Arrays store values or elements of the same data type, whereas array lists store values of various data types.

Arrays will use a fixed length, whereas array lists will not.

 

7. What exactly are Jagged Arrays?

Ans: In C#, an array with arrays as its elements is called a jagged array. A ragged array can have pieces of various shapes and sizes. An "array of arrays" is another name for a jagged array. In C#, a unique type of array is presented. A jagged array is a stack of arrays where each array index's length can vary.

 

8. Define constructor in the easiest language constructors.

Ans:A function is a class member function with the same name as the class. When an object class is created, the function is automatically called. While initialising the class, it constructs the values of data members.

 

9. What exactly is the distinction between public, static, and void?

Ans: The distinction between them are following:
Public: Variables and methods declared as public are accessible from anywhere in the application. 

Static: Without creating an instance of the class, static declared variables or methods are globally accessible. Static members are not globally accessible by default; it depends on the type of access modification used. The compiler saves the method's address as the entry point and uses it to start execution before any objects are created. 

Void: It is a type modifier that indicates that the method or variable returns null.

 

10. In C#, What are partial classes?

Ans: Partially implemented classes distribute the functionality of a single class across multiple files. During the compilation process, these multiple files are combined into one. The partial keyword is used to create the partial class.

public partial Class_name{
 // code
}


Methods, interfaces, and structures' functionalities can be easily separated into multiple files. You can also include nested partial classes.

 

11. What exactly are Indexers in C#?

Ans: Smart arrays are indexers that allow access to a member variable. Indexers make array features available to member variables. They are made with the Indexer keyword. Indexers are not permanent members.

<return type> this[<parameter type> index]
{
   get{
       // return the value from specified index of an internal collection
   }
   set{
       // set values at specified index in an internal collection
   }
}

 

12. What is the difference between Custom Control and User Control?

Ans: Custom Controls are compiled code (DLL) controls that are easier to use and can be added to the toolbox. Developers can add controls to their web forms by dragging and dropping them. Attributes can be added during the design process. Custom controls can be easily added to multiple applications (If Shared Dlls). So, if they are private, we can copy the dll to the web application's bin directory, add a reference, and use them.

User Controls are similar to ASP, including files in that they are simple to create. User controls cannot be dragged and dropped into the toolbox. They have their own design and code. Ascx is the file extension for user controls.

Also see, System Design Interview Questions

 

13. What is the distinction between System.String and System.Text.StringBuilder?

Ans: Systems.Strings are unchangeable. When we change the value of a string variable, we allocate new memory to the new value and release the previous memory allocation. System.Text.StringBuilder was created with the concept of a mutable string in mind, allowing a variety of operations to be performed without the need for a separate memory location for the modified string.

 

14. What exactly is reflection in C#?

Ans: During runtime, C# reflection extracts metadata from data types.

To implement reflection in the .Net framework, simply use the System.Reflection namespace in your program to retrieve the type, which can be any of the following:

  • Assembly
  • ConstructorInfo
  • MemberInfo
  • ParameterInfo
  • FieldInfo
  • EventInfo
  • PropertyInfo

 

15. Why is the "finally" block used in C#?

Ans: The "Finally" block will be executed regardless of the exception. When an exception occurs while executing the code in the try block, control is returned to the catch block, and the "finally" block is executed. As a result, closing the database connection and releasing the file handlers can be kept in the "finally" block.

 

16. In C#, what is the difference between the "out" and "ref" parameters?

Ans: The "out" parameter can be passed to a method without being initialized, whereas the "ref" parameter must be initialized before it can be used.

 

17. What is the purpose of 'Data Type Conversion' in C#?

Ans: The purpose of data type conversion is to avoid situations of runtime error during data type change or conversion.

 

18. What is the GAC, and where can I find it?

Ans: The Global Assembly Cache is abbreviated as the GAC. Shared assemblies are stored in the GAC, allowing applications to share assemblies rather than having them distributed with each application. Thanks to versioning, multiple assembly versions can exist in the GAC—applications can specify version numbers in the config file. To manage the GAC, use the gacutil command line tool.

 

19. What is a circular reference in C#?

Ans: This is a situation in which multiple resources depend on each other, resulting in a lock condition and unused resources.

 

20. What exactly is an Object Pool in.Net? What does it imply?

Ans: Object Pooling in.NET allows objects to be kept in a memory pool and reused without having to recreate them. This article defines object pooling in.NET and shows how to implement it in C#.

Object Pool is a container for ready-to-use objects. Whenever a new object is requested, the pool manager accepts the request and fulfills it by allocating an object from the pool.

 

21. Explain Accessibility Modifiers in C#.

Ans: Access modifiers are keywords that specify the level of accessibility of a type member or the type itself. A public class, for example, is available to the entire world, whereas an internal class may be available only to the assembly.

 

22. What exactly are Anonymous Types in C#?

Ans: Anonymous types enable us to create new types without having to define them. This method defines read-only properties in a single object without explicitly defining each type. Type is generated by the compiler and is only available for the current block of code. The compiler also infers the type of properties.

 

23. What is the distinction between the methods Finalize() and Dispose()?

Ans: When we want an object to release unmanaged resources, we call dispose(). Finalize(), on the other hand, serves the same purpose but does not guarantee garbage collection of an object.

 

24. What exactly are Custom Exceptions?

Ans: There are times when errors must be handled in accordance with user requirements. Custom exceptions and defined exceptions are used for them.

 

25. What exactly are delegates?

Ans: Delegates are similar to function pointers in C++, except that, unlike function pointers, they are type safe. Delegates are required because they allow for creating far more generic type-safe functions.

 

26. Write a program in C# to find if a positive integer is prime or not?

Ans: 

static void Main(string[] args) 
{ 
    if (FindPrime(47)) 
    { 
        Console.WriteLine("Prime"); 
    } 
    else 
    { 
        Console.WriteLine("Not Prime"); 
    } 
    Console.ReadLine(); 
}   
internal static bool FindPrime(int number) 
{ 
    if (number == 1) return false; 
    if (number == 2) return true; 
    if (number % 2 == 0) return false; 
     var squareRoot = (int)Math.Floor(Math.Sqrt(number)); 
     for (int i = 3; i <= squareRoot; i += 2) 
    { 
        if (number % i == 0) return false; 
    } 
     return true; 
}

 

27. Write a program in C# to find the substring from a given string?

Ans:

internal static void findallsubstring(string str) 
{ 
   for (int i = 0; i < str.Length; ++i) 
   { 
       StringBuilder subString = new StringBuilder(str.Length - i); 
       for (int j = i; j < str.Length; ++j) 
       { 
           subString.Append(str[j]); 
           Console.Write(subString + " "); 
       } 
   } 
}

 

28. Write a program in C#  to reverse the order of the given words?

Ans:

internal static void ReverseWordOrder(string str) 
{ 
  int i; 
  StringBuilder reverseSentence = new StringBuilder(); 
   int Start = str.Length - 1; 
  int End = str.Length - 1; 
   while (Start > 0) 
  { 
      if (str[Start] == ' ') 
      { 
          i = Start + 1; 
          while (i <= End) 
          { 
              reverseSentence.Append(str[i]); 
              i++; 
          } 
          reverseSentence.Append(' '); 
          End = Start - 1; 
      } 
      Start--; 
  } 
   for (i = 0; i <= End; i++) 
  { 
      reverseSentence.Append(str[i]); 
  } 
  Console.WriteLine(reverseSentence.ToString()); 
}

 

29. What is Console application?

Ans: An application that may be run in Windows command prompt is referred to as a console application. Building a console application is ideally the first step for any .Net beginner to take.

 

30. Is C# code is managed or unmanaged code?

Ans: Because the Common Language Runtime can convert C# code to Intermediate language, therefore C# is considered managed code.

Also check out Embedded C Interview Questions and Selenium Interview Questions.

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Frequently Asked Questions

What are the most important things that you must do in an interview?

There are a few points that you have to remember, they are:

  • Do Enough Research on the Company
  • Be On-Time for the Interview
  • Be Respectful of the interviewer
  • Good Non-Verbal Behavior.
     

What are all the C# important topics for an experienced interview?

The important topics from C#.NET are listed below:

  • CLR.
  • CLS.
  • CTS.
  • .NET Framework
  • Classes and objects
  • OOP’s
  • Difference b/w Abstract & Interface.
     

What is Garbage collection in c#?

The garbage collector (GC) is in charge of memory allocation and release. The garbage collector is a memory manager that runs in the background. You don't need to know how to allocate and release memory or how to manage the lifetimes of the things that use it.

Also Read About - singleton design pattern in c#

Conclusion

In this article, we have extensively discussed basic C# interview questions for 5 years experience, intermediate C# interview questions for 5 years experience, along with advanced C# interview questions for 5 years experience.

We hope that this blog has helped you enhance your knowledge about the C# interview questions for 5 years experience and if you would like to learn more, check out our articles C#C# interview questions.NET Framework, and many more on our Coding Ninjas Studio.

Explore more interview questions related articles:

Check out Accenture Interview Experience to learn about their hiring process.

You can also check Interview Experiences and Interview Preparation Resources if you are interested in cracking the technical interviews at top Product-based companies like Amazon, Microsoft, Uber, etc.

Upskill yourself in Data Structures and Algorithms, Competitive Programming, JavaScript, System Design, and more with our Coding Ninjas Studio Guided Path.

Do upvote our blogs if you find them helpful and engaging!

Happy Learning!

Previous article
Accenture HR Interview Questions and Answers
Next article
Top Cloud Computing Interview Questions & Answers (2023)
Live masterclass