Skip to main content

Stage 3 - Loops, Arrays, and Methods

Q12. What is a loop?

Quick interview answer: A loop repeats a block of code until a condition is completed. For example, we can use a loop to print all student names or calculate total marks for all subjects.

for (int i = 1; i <= 5; i++)
{
Console.WriteLine(i);
}

Study in detail: Loops - This article expands the topic with complete explanation, examples, and practice code.

Q13. What is the difference between for and foreach?

Quick interview answer: Use for when you need the index number or when you control the start, end, and increment. Use foreach when you simply want to read each item from a collection.

Study in detail: Loops - This article expands the topic with complete explanation, examples, and practice code.

Q14. What is an array?

Quick interview answer: An array stores multiple values of the same type under one name. Its size is fixed after creation, so it is good when we know the number of items in advance.

Study in detail: Arrays - This article expands the topic with complete explanation, examples, and practice code.

Q15. What is the difference between array and List<T>?

Quick interview answer: An array has a fixed size, so it cannot grow after creation. List<T> is dynamic, so we can add and remove items. In real projects, List<T> is used more often.

Study in detail: Arrays and Collections - This article expands the topic with complete explanation, examples, and practice code.

Q16. What is a method?

Quick interview answer: A method is a named block of code that performs one job. Methods help us reuse code, keep programs organized, and avoid writing the same logic again and again.

Study in detail: Methods - This article expands the topic with complete explanation, examples, and practice code.

Q17. What is method overloading?

Quick interview answer: Method overloading means creating multiple methods with the same name but different parameters. C# chooses the correct method at compile time based on the arguments we pass.

Study in detail: Methods and Override vs Overload - This article expands the topic with complete explanation, examples, and practice code.

nexcoding.in