Search This Blog

Monday, October 28, 2013

C# Interview Questions: How can prevent a class from being inherited?

C# Interview Questions

Question:

How can prevent a class from being inherited?

Answer:
 
Using keyword sealed





What is the default access modifier for interface members?

C# Interview Questions

Question:

What is the default access modifier for interface members?

Answer:

Public





.NET Framework

The .NET Framework is a development framework build by Microsoft for building apps for Windows, Windows Phone, Windows Server, and Windows Azure.

Components
  • common language runtime (CLR)
  • .NET Framework class library
The .NET Framework is a managed execution environment.





NET Framework Garbage Collector

.NET Framework > Garbage Collector

The .NET Framework garbage collector manages the allocation and release of memory for applications.
When you create a new object the CLR allocates memory for the object in a managed heap. 
The runtime continues to allocate space for new objects.
Because the memory is not infinite the garbage collector performs a collection in order to free some memory. 

Advantages:
  • don't have to free memory
  • effectively allocate objects  on the managed heap
  • clears memory of the objects no longer being used
  •  memory safety

Friday, October 25, 2013

Float type in C#

C# > Types > Float

Float is a simple type that stores 32-bit floating-point values.

By default, a float on the right side of the assignment operator is treated as double.
If you do not use the suffix F, you will get a compilation error because you are trying to store a double value into a float variable:

float x = 7.5; // Error Literal of type double cannot be implicitly converted to type 'float'; use an 'F' suffix to create a literal of this type

To initialize a float variable, use the suffix f or F:

float x = 7.5F; // Ok





Char type in C #

Types in C# > Char

Char type in C# declares a Unicode character.
Unicode characters are 16-bit characters that are used to represent most of the known written languages throughout the world.

Example of char:

1.
char[] chs = new char[2];
chs[0] = 'U'; // Character literal
chs[1] = (char)85; // Cast from integral type
foreach (char c in chs)
   MessageBox.Show(c.ToString());

2. Null Char




Thursday, October 24, 2013

Bool Type C Sharp

C# > Types > Bool

bool type in C# it is used to declare variables to store the Boolean values, true and false.

Examples:

bool b = true;
MessageBox.Show(b.ToString()); // Display True

b = null; //Error: Cannot convert null to 'bool' because it is a non-nullable value type

If you need a Boolean variable that can also have a value of null, use bool?

bool? b = true;
b = null; //Ok