MyInternships.in

C# Basics — Questions and Answers

C# questions in Indian service-company hiring focus on the .NET type system rather than on advanced language features. Value types versus reference types, boxing, the difference between a struct and a class, string immutability, and what the CLR and garbage collector actually do together account for most of what a fresher is asked.

8 solved questionsC# ProgrammingFree · no signup

C# Basics— Concepts, Formulas & Shortcuts

  • Value types (int, float, bool, struct, enum) live on the stack; reference types (class, string, array, delegate) live on the heap.
  • Boxing converts a value type to object (heap allocation); unboxing converts it back with an explicit cast.
  • string is a reference type but behaves immutably — every modification creates a new object; use StringBuilder for loops.
  • A struct is a value type and cannot inherit from another struct or class; a class is a reference type and supports inheritance.
  • The CLR provides JIT compilation, type safety, exception handling and automatic garbage collection.
  • var is compile-time inferred and strongly typed; it is not the same as dynamic, which defers type resolution to run time.

C# Basics Practice Questions with Answers

Attempt each question first, then open the explanation. All 8 questions below are free to read and require no signup.

  1. Q1.Which of the following is a value type in C#?

    Easy
    • Astring
    • Bclass
    • Cint
    • Darray
    +Show Answer & Explanation

    Answer: C. int

    Explanation: int is a value type stored inline. string, class instances and arrays are all reference types.

    C# Basics question 1 of 8
  2. Q2.Boxing in C# refers to:

    Moderate
    • AConverting a value type to a reference type
    • BConverting a reference type to a value type
    • CWrapping a class in an interface
    • DEncrypting an object
    +Show Answer & Explanation

    Answer: A. Converting a value type to a reference type

    Explanation: Boxing allocates the value type on the heap inside an object; unboxing is the reverse and requires an explicit cast.

    C# Basics question 2 of 8
  3. Q3.Which keyword is used to prevent a class from being inherited in C#?

    Easy
    • Astatic
    • Bsealed
    • Cfinal
    • Dconst
    +Show Answer & Explanation

    Answer: B. sealed

    Explanation: sealed prevents inheritance. (final is the Java equivalent and is not a C# keyword.)

    C# Basics question 3 of 8
  4. Q4.What does the CLR stand for in .NET?

    Easy
    • AClass Library Reference
    • BCommon Language Runtime
    • CCompiled Language Resource
    • DCentral Logic Registry
    +Show Answer & Explanation

    Answer: B. Common Language Runtime

    Explanation: The Common Language Runtime executes .NET code, providing JIT compilation, type safety, memory management and garbage collection.

    C# Basics question 4 of 8
  5. Q5.To build a string inside a large loop efficiently, you should use:

    Moderate
    • Astring concatenation with +
    • BStringBuilder
    • Cstring.Copy
    • Dchar array
    +Show Answer & Explanation

    Answer: B. StringBuilder

    Explanation: Strings are immutable, so repeated concatenation allocates a new object each time. StringBuilder mutates one internal buffer.

    C# Basics question 5 of 8
  6. Q6.A struct in C# differs from a class in that it:

    Moderate
    • ASupports inheritance
    • BIs a value type
    • CIs always static
    • DCannot have methods
    +Show Answer & Explanation

    Answer: B. Is a value type

    Explanation: A struct is a value type: it is copied on assignment and cannot inherit from another struct or class, though it can have methods and implement interfaces.

    C# Basics question 6 of 8
  7. Q7.Which statement about "var" in C# is correct?

    Moderate
    • AIt is dynamically typed at run time
    • BIts type is inferred at compile time and cannot change
    • CIt is the same as object
    • DIt can only hold strings
    +Show Answer & Explanation

    Answer: B. Its type is inferred at compile time and cannot change

    Explanation: var is implicit typing resolved by the compiler; the variable is still strongly and statically typed. dynamic is the run-time alternative.

    C# Basics question 7 of 8
  8. Q8.Which .NET feature automatically reclaims memory of unreachable objects?

    Easy
    • AJIT compiler
    • BGarbage collector
    • CAssembly loader
    • DDestructor queue
    +Show Answer & Explanation

    Answer: B. Garbage collector

    Explanation: The garbage collector runs on the managed heap and frees objects with no remaining references, using a generational algorithm.

    C# Basics question 8 of 8

C# Basics — Frequently Asked Questions

What is the difference between a struct and a class in C#?+

A struct is a value type, stored inline and copied on assignment, cannot inherit and has an implicit parameterless constructor. A class is a reference type stored on the heap, copied by reference and supports inheritance and polymorphism.

What is boxing in C#?+

Wrapping a value type inside an object reference so it can be stored on the heap. It costs an allocation, so heavy boxing in loops is a common performance problem — generics were introduced largely to avoid it.

Cleared the aptitude round? Now grab the role.

Preparation only pays off when you apply. Thousands of internships and fresher jobs across India are live on MyInternships.in right now — free to apply, no consultancy fees.