OOPS & C# - Important Keywords

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall with Kai
GameKnowt Play
New
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/23

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

24 Terms

1
New cards

What is “this” keyword in C#?

this keyword is used to refer to the CURRENT INSTANCE of the class.

2
New cards

When to use it in real applications?

this keyword avoids the name confusion between class fields and constructor parameters.

3
New cards

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();
        }
    }
}

4
New cards

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.

5
New cards

What is the difference between “is” and “as” operators?

6
New cards

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.

7
New cards

What is the difference between “Readonly” and “Constant” variables (atleast 3)?

Feature

const

readonly

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

const

readonly

When value is fixed

Compile time

Runtime

8
New cards

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.

9
New cards

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.

10
New cards

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.

11
New cards

What is Enum keyword used for?

An enum is a special "class" that represents a group of constants

12
New cards

Is it possible to inherit Enum in C#?

Enum is a sealed class type, so it cannot be inherited.

13
New cards

What is the use of Yield keyword in C#?

The yield keyword will act as an iterator blocker and generate or return values.

14
New cards
15
New cards
16
New cards
17
New cards
18
New cards
19
New cards
20
New cards
21
New cards
22
New cards
23
New cards
24
New cards