1/23
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What is “this” keyword in C#?
this keyword is used to refer to the CURRENT INSTANCE of the class.
When to use it in real applications?
this keyword avoids the name confusion between class fields and constructor parameters.
What is the purpose of “using” keyword in C#?
1. USING DIRECTIVE
2. USING STATEMENT - The using statement ensures that DISPOSE() method of the class object is called even if an exception occurs
using System.Data.SqlClient; // Directive
class Program
{
static void Main()
{
// using statement
using (var connection = new SqlConnection("ConnectionString"))
{
var query = "UPDATE YourTable SET Property = Value";
var command = new SqlCommand(query, connection);
connection.Open();
command.ExecuteNonQuery();
}
}
}
Can we use Using keyword with other classes apart from DBConnection?
Yes, using keyword can be used with any class which is inherited from IDisposable class. For example, with StreamReader class.
What is the difference between “is” and “as” operators?
Is
The IS operator is USED TO CHECK be type of an object.
The IS operator will return boolean type
As
AS operator is used to PERFORM CONVERSION between compatible reference type.
What is the difference between “Readonly” and “Constant” variables (atleast 3)?
Feature |
|
|
---|---|---|
Assignment timing | Must be assigned at declaration | Can be assigned at declaration or in constructor |
Can value be changed later? | ❌ No | ✅ Only in constructor |
Keyword used |
|
|
When value is fixed | Compile time | Runtime |
What is “Static" class?
A static class in C# is a class that:
Cannot be instantiated — you can't use new
to create an object of it.
Contains only static members — all fields, properties, and methods must be marked static
.
Use of static class:
Static classes are used as containers for static members like methods, constructors and others.
Is typically used for utility or helper methods that don’t require object state.
What is the difference between “var” and “dynamic” in C#?
VAR - The type of the variable is decided by the compiler at compile time.
DYNAMIC - The type of the variable is decided at run time.
What is Enum keyword used for?
An enum is a special "class" that represents a group of constants
Is it possible to inherit Enum in C#?
Enum is a sealed class type, so it cannot be inherited.
What is the use of Yield keyword in C#?
The yield keyword will act as an iterator blocker and generate or return values.