*
Previous C# Question Answers-91 - 100 C# Question Answers-111 - 120 Next

C# (C-Sharp) Question Answers - 101-110

101. What is strong-typing versus weak-typing? Which is preferred? Why?

Strong typing: Type of variables checked at compile time. Prevents mixing operations between mismatched types. Strong-typed language: variables known at compile time, strict type enforcement, compile-time errors for violations.

Weak typing: Type checking delayed to runtime. Types can be mixed without explicit conversion. Preferred: depends on context. For scripts, weak typing is easier; for large programs, strong typing reduces errors.

102. What is the base class of .NET objects?

System.Object is the base class in C#.

103. What is the difference between a Struct and a Class?

  • Structs are value types stored on stack; Classes are reference types stored on heap.
  • Structs do not support inheritance; Classes support inheritance.
  • Structs do not support Anonymous Types; Classes do.
  • Classes can be static; Structs cannot.
  • Both support Partial, constructor, instantiation, initialization.
  • Both can implement interfaces.
  • Both can be nested within another class or struct.
  • Both can contain static members.
  • Both can contain methods.
  • Both can be used as parameters.

104. What is the difference between a thread and a process?

Thread is the part of Process.
One process may have many Threads.

Each process provides the resources needed to execute a program. A process has a virtual address space, executable code, open handles to system objects, a security context, a unique process identifier, environment variables, a priority class, minimum and maximum working set sizes, and at least one thread of execution. Each process is started with a single thread, often called the primary thread, but can create additional threads from any of its threads.

A thread is the entity within a process that can be scheduled for execution. Threads can also have their own security context, which can be used for impersonating clients.

105. What is the difference between a.Equals(b) and a == b?

Value types: Both compare values. Reference types: == compares references; Equals() compares content/value.

106. What is the difference between an EXE and a DLL?

Exe has an entry point whereas DLL does not have an entry point.
Both are executable code.
Exe is an executable and independent program/process to run which has its own reserved memory space, whereas DLL (Dynamic Link Library) is neither executable nor independent—it is used by other DLLs or programs.

.exe

  • Is an executable file
  • It can be run independently
  • It has an execution entry point
  • It cannot be reused by other applications
  • When a system launches a new executable, a new process is created

.dll

  • It's a Dynamic Link Library
  • It is used by other DLLs or EXE applications
  • It does not have an execution entry point
  • It can be reused by other applications
  • The system loads a DLL into the context of an existing process which is calling this dll.

107. What is the difference between Finalize() and Dispose()?

Finalize Method

The finalizer method is called when your object is garbage collected, and you have no guarantee when this will happen. Although it can be forced to execute, doing so impacts performance. This method belongs to the Object class and is implemented using a destructor.

Dispose Method

The Dispose method is meant to be called by the code that created your class so that you can clean up and release any resources you have acquired— such as unmanaged data, database connections, or file handles—immediately after the object is no longer needed. This method belongs to the IDisposable interface and is implemented by defining the Dispose() method.

Using Statement

By using the using statement, we can handle the Dispose method internally. When an object is used within a using block, its Dispose method is called automatically at the end of the block.

108. What is the difference between typeof(foo) and myFoo.GetType()?

typeof() gives compile-time type. GetType() gives runtime type.

109. Difference between catch(Exception e){throw e;} and catch(Exception e){throw;}

throw; rethrows exception keeping stack trace. throw e; creates new exception, resets stack trace.

110. What is the JIT? What is NGEN? Limitations and benefits?

What is JIT?

JIT (Just-In-Time Compiler) compiles methods at runtime as they are needed. It converts Intermediate Language (IL) code into native machine code during execution.

Benefits of JIT

  • Optimizes code based on runtime context
  • Supports platform independence
  • Reduces initial deployment size

Limitations of JIT

  • Introduces a small startup delay due to runtime compilation
  • Performance hit during method execution for the first time
  • Not ideal for performance-critical startup scenarios

What is NGEN?

NGEN (Native Image Generator) compiles assemblies ahead-of-time during installation, producing native images that are stored in the native image cache.

Benefits of NGEN

  • Eliminates JIT compilation overhead at runtime
  • Improves startup performance
  • Reduces memory usage by sharing native images across processes

Limitations of NGEN

  • Native images are platform-specific
  • Less flexible for runtime optimizations
  • Requires additional maintenance during deployment
Back to Index
Previous C# Question Answers-91 - 100 C# Question Answers-111 - 120 Next
*
*