C# Interview Questions and Answers (958) - Page 38

What do you mean by name hiding in C# programming language?

In some scenarios, we can have both the inner and outer namespaces containing the types with the same name. At this point, name hiding is used.
It states that the priority is given to the type that is present in the inner namespace.

Example,
namespace Home

{
namespace Hall
{
class Television { }
class Furniture { }
namespace DiningRoom
{
class Furniture { }
class Color
{
Furniture DiningFurniture; // Hall.DiningRoom.Furniture (Because of higher priority)
Hall.Furniture HallFurniture; // Hall.Furniture
}
}
}
}

What do you mean by repeated namespaces in C# programming language?

There is a possibility of repeating namespaces until the types of that namespace doesn't get conflict.

Example,
namespace Home.Hall.Television

{
class Channel1 { }
}
namespace Home.Hall.Television
{
class Channel2 { }
}

We can also divide the above example as two source files such as,

Channel-1:
namespace Home.Hall.Television

{
class Channel1 { }
}

and,

Channel-2:
namespace Home.Hall.Television

{
class Channel2 { }
}

What do you mean by using keyword in C# programming language?

using is a directive/keyword which is used to import a namespace. It provides access to refer all the types in that particular namespace.

Example,
using Home.Hall.DiningRoom;


class MyClass
{
static void Main()
{
Furniture Chairs, Tables; // Refering Furniture type from the namespace above.
}
}

What is the use of 'else' statement in C# programming language?

else is a selection statement used with if statement to execute the alternate conditions of if statement.

Example,
int x = 10, y = 5;

if (x == y)
{
Console.WriteLine("Both x and y are equal....");
}
else
{
Console.WriteLine("Both x and y are not equal....");
}

What do you mean by switch and case statements in C# programming language?

These both are the selection statements used to together to perform switch operations. In other words, switch is used to execute particular section (case) of the statement.

Example,
string Name = "Krishna";

switch (Name)
{
case "Krishna": // This case will be executed...
...............;
break;
case "Vamshi":
...............;
break;
default:
...............;
break;
}


For every case, break should be used to terminate the execution and let it go to the next case.
What do you mean by do and while statements in C# programming language?

Similar to 'switch and case' statements, do executes the entire statement block repeatedly until it meets a false evaluation which is stated by while.

Example,
int x = 3;

do
{
Console.WriteLine(a); // This will print from 3 to 8 (because of while)
a++;
}
while (a < 9);

What is the use of 'for' statement in C# programming language?

for is an iteration statement that executes the entire block repeatedly like do statement without using any other statements like while.

Example,
for (int i = 1; i < 9; i++)

{
Console.WriteLine(i); // This will print from 1 to 8
}

What is the use of 'foreach' statement in C# programming language?

foreach is an important statement used in C# and .NET frameworks. It is similar with for statement but it cannot be used to add or remove source items.

Example,
foreach (char t in "Dotnetfunda")

{
Console.WriteLine(t); // This will prints all the 't's present in that string
}

We can also use break and continue keywords to control the execution like play and pause.
foreach can also be excited by some other jump statements such as throw, return etc.
Which keyword is used to start the execution from certain point or line of the statement?

NOTE: This is objective type question, Please click question title for correct answer.
Which keyword is used to terminate the execution at particular stage of a statement?

NOTE: This is objective type question, Please click question title for correct answer.
Which keyword is used to exit a method by returning an expression of particular type in C#?

NOTE: This is objective type question, Please click question title for correct answer.
Which keyword is used to throw an exception by indicating that an error is occurred?

NOTE: This is objective type question, Please click question title for correct answer.
Which keyword is used to transfer the execution of a program directly to another label?

NOTE: This is objective type question, Please click question title for correct answer.
What do you mean by virtual modifier in C# programming language?

In order to modify any type or field and allow that to override by any other derived class, virtual modifier is used. A virtual method can be accessed by any derived classes and can redefine it.

Example,
class MyClass

{
protected virtual void Test() // Virtual method declaration
{
..............;
............;
}
}
class SubClass : MyClass
{
protected override void Test() // overriding method from 'MyClass' class
{
..............;
............;
}
}

What do you mean by const modifier in C# programming language?

It is used to declare constants which cannot be modified. In C#, mostly we declare the const for numeric types, value types, strings etc.
Only way to modify a constant field is to do that at compile time only as const keyword restricts the field from being modified in the runtime.

Example,
const string Site = "DotNetFunda"; // Declaration of constant field

Site = "ITFunda"; // Compile time error

What do you mean by 'event' modifier in C# programming language?

event modifier is used to declare any events by using handlers. This modifier is generally used in notification systems where we need to have number of event types.
Any changes and other implementations can be done without disturbing the remaining code of the application.

Example,
public static event EvtHandler MyEvent; // EvtHandler must have been specified outside by using 'delegate' keyword. 


static void Main()
{
MyEvent = new EvtHandler(MeetFriends); //Adding notification to the event
MyEvent.Invoke(); //Invoking the event
}

static void MeetFriends()
{
..........;
.........;
}

C# reference used to initialize and declare any type of variables is?

NOTE: This is objective type question, Please click question title for correct answer.
In C#, the expression which doesn't perform any operations is known as?

NOTE: This is objective type question, Please click question title for correct answer.
What are the primary expressions in C# programming language?

Primary expressions are the simple expressions which include the expressions composed by using operators.

Example,
Math.Equals(....)

In the above example, we combined two primary expressions with '.' operator.
What are the assignment expressions in C# programming language?

Assignment expressions store the result to a variable after performing operation.
In other words, they assign the value (after the action) to a variable by using '=' operator.

Example,
int x = 5;  // Assignment Expression : x = 5

x = x + 10; // Assignment Expression : x = 15
In the above example, we are assigning value to 'x'.
Also adding another value (10) and storing it back to 'x'.
Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Interview Questions and Answers Categories