Home Interview Questions and AnswersTechnical Interview Questions and Answers.NET .Net Programming Concepts Interview Questions and Answers for Freshers and Experience Part-2

.net7. Differentiate between the while and for loop in C#.
The while and for loops are used to execute those units of code that need to be repeatedly executed, unless the result of the specified condition evaluates to false. The only difference between the two is in their syntax. The for loop is distinguished by setting an explicit loop variable.

8. What is an identifier?
Identifiers are northing but names given to various entities uniquely identified in a program. The name of identifiers must differ in spelling or casing. For example, MyProg and myProg are two different identifiers. Programming languages, such as C# and Visual Basic, strictly restrict the programmers from using any keyword as identifiers. Programmers cannot develop a class whose name is public, because, public is a keyword used to specify the accessibility of data in programs.

9. What does a break statement do in the switch statement?
The switch statement is a selection control statement that is used to handle multiple choices and transfer control to the case statements within its body. The following code snippet shows an example of the use of theswitch statement in C#:
case 1:
case 2:
console.WriteLine(“Wrong choice”);
In switch statements, the break statement is used at the end of a case statement. The break statement is mandatory in C# and it avoids the fall through of one case statement to another

10. Explain keywords with example.
Keywords are those words that are reserved to be used for a specific task. These words cannot be used as identifiers. You cannot use a keyword to define the name of a variable or method. Keywords are used in programs to use the features of object-oriented programming.

For example, the abstract keyword is used to implement abstraction and the inherits keyword is used to implement inheritance by deriving subclasses in C# and Visual Basic, respectively.
The new keyword is universally used in C# and Visual Basic to implement encapsulation by creating objects.

11. Briefly explain the characteristics of value-type variables that are supported in the C# programming language.
The variables that are based on value types directly contain values. The characteristics of value-type variables that are supported in C# programming language are as follows:
All value-type variables derive implicitly from the System.ValueType class
You cannot derive any new type from a value type
Value types have an implicit default constructor that initializes the default value of that type
The value type consists of two main categories:
Structs – Summarizes small groups of related variables.
Enumerations – Consists of a set of named constants.

12. Give the syntax of using the while loop in a C# program.
The syntax of using the while loop in C# is:
while(condition) //condition
You can find an example of using the while loop in C#:
int i = 0;
while(i < 5)
Console.WriteLine(“{0} “, i);
The output of the preceding code is: 0 1 2 3 4 .

You may also like

Leave a Comment