Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 30th, 2006, 08:19 AM
Registered User
 
Join Date: Aug 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to hpatel_it Send a message via Yahoo to hpatel_it
Default Some confusion in these code

Hi,

I have read out one sample online article about Interface & Abstract Class. In that article all are mentioned in good way and easily understandable but I have a problem in understanding following code.

Article Link :
http://www.codeproject.com/csharp/A...SInterfaces.asp

In Following code, Lines which are marked by RED color its not understandablel by me.

In short , in first function why we need to use Casting and while in second function why we dont need to use casting.

Can you please help me out for this ?

Code :

private void InterfaceExample_Click(object sender,
System.EventArgs e)
{
try
{

IEmployee emp;

Emp_fulltime2 emp1 = new Emp_fulltime2();
//has to be casted because of the interface!
emp = (IEmployee) emp1;
emp.ID = "2234";
emp.FirstName= "Rahman" ;
emp.LastName = "Mahmoodi" ;
//call add method od the object
MessageBox.Show(emp.Add().ToString());

//call the CalculateWage method
MessageBox.Show(emp.CalculateWage().ToString());


}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}

}

private void cmdAbstractExample_Click(object sender,
System.EventArgs e)
{

Employee emp;
//no casting is requird!
emp = new Emp_Fulltime();

emp.ID = "2244";
emp.FirstName= "Maria" ;
emp.LastName = "Robinlius" ;
MessageBox.Show(emp.Add().ToString());

//call the CalculateWage method
MessageBox.Show(emp.CalculateWage().ToString());

}

Thanks,
Hiren Patel





Similar Threads
Thread Thread Starter Forum Replies Last Post
Errata confusion morganstein BOOK: Visual Basic 2008 Programmer's Reference ISBN: 978-0-470-18262-8 0 October 10th, 2008 05:11 PM
Confusion with PLATFORM, Help me Please! dpkbahuguna .NET Framework 2.0 10 September 28th, 2007 08:41 AM
foreach confusion stokerfed C# 2 June 13th, 2007 02:30 PM
.net Confusion reyboy General .NET 1 December 29th, 2004 08:35 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.