OOPS & C# - Loops, Conditions, Exception Handling

0.0(0)
studied byStudied by 0 people
full-widthCall with Kai
GameKnowt Play
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 are the Loop types in C#?

  1. While loop

  2. Do While

  3. For Loop

  4. ForEach Loop

2
New cards

What is the difference between “continue” and “break” statement?

  • Continue statement end the loop iteration and transfer the control to the beginning of the loop.

  • Break statement end the loop iteration and exit the loop.

3
New cards

What are the alternative ways of writing if-else conditions?

  1. Switch

  2. Ternary

4
New cards

How to implement Exception Handling in C#?

Exception handling with Try, Catch, and Finally

5
New cards

Can we execute multiple Catch blocks?

NO

6
New cards

When to use Finally in real applications?

Finally block is mostly used to dispose the unwanted objects

7
New cards
8
New cards

Can we have only “Try” block without “Catch” block in real applications?

YES - but then we must have finally block with try block.

9
New cards

What is the difference between Finally and Finalize?

❖ Finally, is used in exception handling.

❖ Finalize is a method which is automatically called by the garbage collector to dispose the no longer needed objects

10
New cards
11
New cards

What is the difference between “throw ex” and “throw”?

Throw ex will change the stack trace, where as throw will preserve the whole stack trace.

12
New cards

Explain Generics in C#?

Make classes and methods - type independent or type safe.

EX: AreEqual<T>(T value1, T value2)

13
New cards

What are Collections in C# and what are their types?

Used to store, manage and manipulate data

EX: ArrayList, Dictionary, List, Hashtable

14
New cards

What is the difference between Array and ArrayList (atleast 2)?

  1. Array is STRONGLY typed

  2. Array elements are FIXED

  1. ArrayList can Store any items\elements

  2. ArrayList can store any amount of elements

15
New cards

What is the difference between Arraylist and Hashtable?

  • In Arraylist we can only add Items/ Values to the list.

    • Values

  • In Hashtable we can add Items/Values with the Keys.

    • Keys and Value

16
New cards

What is the difference between List and Dictionary Collections?

  • List is a collection of items.

  • It is the generic version of ArrayList

  • Dictionary is a collection of key value pair.

  • It is the generic version of Hashtable

17
New cards

What is IEnumerable in C#?

IEnumerable interface is used when we want to ITERATE among our collection classes using a FOREACH loop. 

  • Interface that ITERATE collection in a FOREACH loop

18
New cards

What is the difference between IEnumerable and IEnumerator in C#?

  • IEnumerable internally uses IEnumerator only to iterate the collection via forach loop.

  • IEnumerable simplifies the use of IEnumerator.

19
New cards

What is the difference between IEnumerable and IQueryable in C#?

  • IQueryable inherited from IEnumerable interface only

    • Anything you can do with a IEnumerable, you can also do with an IQueryable also.

  • IEnumerable is used with in-memory collection.

  • IQueryable is better in getting result from database.

  • IQueryable is under SYSTEM.LINQ namespace. IEnuberable is under System.Collections namespace.

  • IQueryable filter the result at database only and then get only filtered result, therefore less network load and better performance.

20
New cards

21
New cards
22
New cards
23
New cards
24
New cards