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

What are the instance members in C# programming?

Instance members are the class members which operate on the instance of a particular type.

In other words, when a method or property declarations does not include any static keyword, then it declares an instance member.

They can be data members or function members.

ToString method of type Int is an example of an instance member.
What are the static members in C# programming?

Static members are the class members which does not operate on any instance of the type.

In other words, when a method or property declaration includes any static modifier (keyword), then it declares a static member.

Static members can be either data or function members.

Console.Write is an example of static member because it is a static class which contains all the static members.
What are the nested types in C#?

In some cases, we may have a class (or struct) inside another class.
That inner class (or type such as struct) is known as a Nested class or Nested type.

Example,
class Outer

{
class Inner // Nested class
{
.........;
........;
}
}
Any class declared outside (such as in a namespace or any compilation unit), is known as Non-Nested class or Non-Nested type.
In C#, the literal used to write the values of int, long, short etc. is?

NOTE: This is objective type question, Please click question title for correct answer.
In C#, literals used to write the true or false for a type is?

NOTE: This is objective type question, Please click question title for correct answer.
In C#, literals used to represent a single character in single quotes is?

NOTE: This is objective type question, Please click question title for correct answer.
In C#, literals used to write the values of float, double and decimal are?

NOTE: This is objective type question, Please click question title for correct answer.
In C#, literal used to write a null type is?

NOTE: This is objective type question, Please click question title for correct answer.
In C#, literal used to represent strings is?

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

In order to group or divide (separate) the code, punctuators are used. They helps to demarcate the program structure.

Example:
Semicolon (;) is a punctuator which is used to terminate (end) a statement.
Braces ({,}) are also the punctuators which are used to group number of statements into a separate block.
class MyClass

{ // Brace
statement1; // Semicolon
statement2;
}

What are operators in C#?

Operators are used to combine the individual statements and to perform an action between them.
C# has so many number of operators depending upon their operands (i.e literals).

Example,
6 + 8
In the above example, we are using addition operator (+).
What do you mean by predefined types in C#?

Predefined types are the special types supported by the compiler.
They include signed, unsigned, bool, decimal, char etc.

Predefined types are generally strings[/I and objects. As we know that object is the base type of all the other types, so it includes all the literal types.
What are the custom types in C#?

Custom types are the complex types which are built by primitive types.
These are created by using class, struct, enum and interface.
Microsoft provided so many custom types to .NET framework that are being used in our own applications.
What is Fixed Keyword in C#?

Fixed is the one of uncommon keyword in C#. The keyword Fixed which can only be used in Unsafe C# code blocks.
Fixed statement sets the pointer to be in a fixed memory address so that,it will not be moved to anywhere even if Garbage Collection Thread is invoked.We have to use Fixed keyword.

For Example:-
fixed (char* pointer = 1)

{
//Our code
}

What is the "Default" Keyword in C#?

Default Keyword returns the default value when the object is not initialized. For example,we all know integers are initialized to 0 if not given any value. Characters are Empty when not given any value,objects are null when not assigned any value.
For Example:-
int x = default(int);//will be assigned to 0.

What do you mean by 'in' keyword in C#?

in is a reserved keyword of C# programming language. in is widely used with foreach loop.

Example,
foreach (char ch in "Hello")

{
Console.WriteLine(ch); // prints all characters
}
in keyword is also used for some query expressions. Ex: LINQ.
What do you mean by extern keyword in C# programming?

extern is a c# keyword or modifier which calls an external method.
It is mostly used for interop services with DLLImport attribute. This will calls an external method from the particular dll library.
Example,
[DllImport("User32.dll", CharSet = CharSet.Unicode)]

public static extern int MessageBox(IntPtr i, string s1, string s2, int type);

static int Main()
{
string Name;
Console.WriteLine("Please type your message here: ");
Name = Console.ReadLine();
return MessageBox((IntPtr)0, Name, "Message Box", 0);
}

What do you mean by async keyword in C# programming?

async is a C# modifier (keyword) used to specify any asynchronous methods. async and await cannot be used with the Main method. async can only return Void or Task. async method can also be run as synchronous if it doesn't include await.

Example,
static async Task<int> FuncAsync()

{
..........;
......;
}

What do you mean by C# Compiler?

It compiles the source code into an assembly. It is named as csc.exe.
We can call the C# compiler manually or by using Visual Studio's IDE (Integrated Development Environment).

To compile manually,
1. We have to save our program with extension of '.cs'

2. And then open the command prompt and invoke the compiler like
RootFolder(Windows Directory)\Microsoft .NET\Framework\
i.e, csc MyProgram.cs. It will generate MyProgram.exe.

3. Now to create a library, do like below,
csc /target:library MyProgram.cs.
Which of the following below is an Identifier of C#?

NOTE: This is objective type question, Please click question title for correct answer.
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