Interview Questions → CSHARP 2.0 → C# 2.0 Questionnaire II
C# 2.0 Questionnaire II
public const int constVal = 2;
public partial class Form1 : Form
{
public readonly int readonlyVal = 2;
public Form1()
{
readonlyVal = 5;
}
}
public void throwException()
{
try
{
int y = 0;
int x = 5 / y;
}
catch (Exception ex)
{
throw new Exception("This is the user friendly message",ex);
}
}
throw new Exception("This is the user friendly message",ex);
Response.Write(ex.Message); -- User Friendly Message
Response.Write(ex.InnerException.Message); -- .net generated message
public void ErrorRoutine()
{
int x = 0;
int y = 5 / x;
}
public void Errorcatchingroutine()
{
try
{
ErrorRoutine();
}
catch (Exception ex)
{
throw;
}
}
string str = string.Empty;
int i = 0;
if (str == i) // This line will give compile time errors.
{
// Some Code
}
if (str.Equals(i)) // This line of code will execute
{
//Some Code
}
StringBuilder sb1 = new StringBuilder("karan");
StringBuilder sb2 = new StringBuilder("karan");
if (sb1.Equals(sb2)) // This condition will return true
{ }
if (sb1 == sb2) // This condition will return false
{}
public interface I1
{
string Display();
string Display(string displayString);
}
public class test : I1
{
public string Display()
{
return "null";
}
public string Display(string displayString)
{
return displayString;
}
}
test obj = new test();
string str1 = obj.Display();
string str2 = obj.Display("Hi");
Response.Write(str1);
Response.Write(str2);
public class Cat
{
public SpeakType Speak()
{
.......
}
}
public class HomeCat : Cat
{
public override SpeakType Speak()
{
.......
}
}
public class StaticClassOne
{
private int variableOne;
private static int variableTwo;
static StaticClassOne()
{
variableTwo = 2;
}
public StaticClassOne()
{
variableOne = 5;
}
}
StaticClassOne obj = new StaticClassOne();
obj = new StaticClassOne();