Posted on 01 April 2013.
Note: The real advantage of interface is not for supporting multiple inheritance.
Advantage1: We need to declare an interface when we have series of classes which are not having common behavior, still if you want to mandate a method name along with signature and return type and if you want to leave the implementation to the developers of the class.
Advantage2: Interfaces acts as contracts between two developers ( why or how this feature is helpful ?)
Explanation: Assume Developer D1 writing code in class A, this class A requires to call some of the methods present in Class B. Assume class B’s code has to be written by Developer D2. Assume some delay in writing the code happening from Developer D2. In this situation Developer D1 ccanot be able to complete his code since class A’s code is depending on the Class B’s Code. This kind of dependencied between developers code we can avoid by using interfaces .
Q:How to avoid Dependency?
Ans: Developer 1 D1 has to create an interface I1 with the required method names and signatures along with return types which D1 wanted to use present in Class B, then ask Developer 2 D2 to implement interface I1 in class B.
Public inteface I1
{
int M1(int x,int y);
}
Public class A
{
public int M2(I1 i1)
{
//wrie some code and call inteface i1′s method M1.
i1.M1(10,20);
}
}
Note: In the above sample D2 has to call the method present in class A by sending his class object as parameter to the method M2.
Posted in .Net Tutorials, C# FAQ, Java
Posted on 06 July 2012.
1. ReferenceEquals and Equals methods behaves same for Reference types but it differs for value types.
2.ReferenceEquals is a Static method and hence we cannot override this method where as Equals method we can override this method.
Ex1:
bool b=0.Equals(0);
bool b1=Object.ReferenceEquals(0, 0);
Response.Write(b);
Ex2:
//Write this code in the main method.
Palle p1 = new Palle(2);
Palle p2 = new Palle(2);
bool b1=p1.Equals(p1);
bool b2=object.ReferenceEquals(p1, p2);
//Both b1 & b2 will be false here
public class Palle
{
public int age;
public Palle(int age)
{
this.age = age;
}
}
Posted in .NET Framework FAQ, C# FAQ
Posted on 20 February 2012.
Dotnet is supported in the below platforms.
- Windows 98 or later versions
- Linux and Mac OS ( Linux and Mac are supported by using Dotnet MONO Project)
Posted in .NET Framework FAQ
Posted on 20 February 2012.
In C# all Custom Exception should be inherited from a class called as ApplicationException.
In the below sample i created a Custom Exception class called CustSalException. I am raising an Exception when some creates an object of Salary class by passing salary value less than 5000.
Please see the below code for the sample. In the code we are also logging the Error message when ever an exception is encoutered into the error log file.
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
int a = 3000;
try
{
Salary ss = new Salary(a);
}
catch (CustSalException cse)
{
File.WriteAllText(@”C:\error.txt”, “Error Message:”+cse.msg);
}
}
}
public class Salary
{
private int _salary;
public Salary(int sal)
{
if (_salary < 5000)
{
CustSalException ee = new CustSalException();
ee.msg = “Salary Should be more than 5000rs”;
throw ee;
}
else
_salary = sal;
}
}
public class CustSalException : ApplicationException
{
public string msg;
}
Posted in .NET Framework FAQ
Posted on 20 February 2012.
Ternary operators can be use full when we have only one simple if else condition.
Ternary Operator Syntax:
condition ? first_expression : second_expression;
Ex:
public class TernaryEx { public int GetBigNum(int a, int b) { return a > b ? a : b; //in the above syntax if a is greater than b //the above expression returns a else it returns b. } }
Note: SignUp for JobGuaranteed Training
Posted in C# FAQ
Posted on 20 February 2012.
is Operator:
- is operator Checks if an object is compatible with a given type
- An is expression evaluates to true if the provided expression is non-null, and the provided object can be cast to the provided type without causing an exception to be thrown.
- The as operator is used to perform conversions between compatible reference types
- The as operator is like a cast operation. However, if the conversion is not possible, as returns null instead of raising an exception
public string GetSubjectName()
public int GetTestNumber()
public partial class CSHARPSAMPLES_Keywords : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
public void Test(object o)
UnitTest u = o as UnitTest;
Posted in C# FAQ
Posted on 20 February 2012.
protected void Page_Load(object sender, EventArgs e)
{
object s1 = “abc”;
object s2 = “abc”;
if (s1 == s2)
{
Response.Write(“value of s1 and s2 are equal”);
}
else if(s1.Equals(s2))
{
Response.Write(“Address of s1 and s2 are equal”);
}
/***************************************************************
* 1.==compares values of the variables.
* 2.Object.Eqals Method compares address of the variables
* **************************************************************/ }
Author: Raghavendra
Click here for job guarantee courses in bangalore
Posted in C# FAQ
Posted on 20 February 2012.
1.Create a webservice and click browse on its .asmx to see the url of the asmx file 2.Open Asp.net application and Right click on the Project Select AddWebreference and give the above generated asmx url , click on Go.

3.Change the Default WebReference name to “Palle” Click on Add Reference.
(OR)
Instead of using Above steps You can Achieve same thing using WSDL.exe
Cosuming WebSerice Using WSDL.EXE:
- After creating the Webservice Right click on .asmx file and Click on Browse
- Copy the url
- Open VS2008 Command prompt
- Follow the steps given in the below given screen shot.

Posted in WebServices
Posted on 16 January 2012.
There are 3 types of .Net Compilers present in .Net Framework.
- Pre-JIT (Compiles entire code into native code at one stretch . In .Net it is called as Ngen.exe)
- Econo-JIT (Compiles code part by part and will be removed once method execution is completed)
- Normal JIT (Compiles only that part of code when called and places in cache)
Posted in .NET Framework FAQ
Posted on 30 November 2010.
See the below example to understand the difference between post incrementation and pre incrementation.
int
x = 10;int z;//First assigns value of x (10) to z and then x value incremented to 11.
z=x++;MessageBox.Show(“Post Incement of x=” + z);int y = 20;int a;
//First increments value of y to (21) and assigns 21 to as.a=++y;
MessageBox.Show(“Pre incrementor Y=”+a);
Posted in C# FAQ
Latest Comments