Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 12th, 2008, 11:40 AM
Registered User
Points: 33, Level: 1
Points: 33, Level: 1 Points: 33, Level: 1 Points: 33, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default missing a using directive or an assembly reference

Hi, I stopped at page 341(Chapter 9: code).
"Inheritance.aspx" is added under the root."Vehicles.cs" is added under the folder "App_Code".

But I got an error
Code:
CS0246: The type or namespace name 'Car' could not be found (are you missing a using directive or an assembly reference?)
Code:
Line 18:     protected void Button1_Click(object sender, EventArgs e)
Line 19:     {
Line 20:         Car myTransport = new Car();
Line 21:         Label4.Text = myTransport.Wheels.ToString();
Line 22:         Label5.Text = myTransport.TopSpeed.ToString();
I guess the code files might be put the appropriate place.
Thanks for your help.
Reply With Quote
  #2 (permalink)  
Old January 12th, 2008, 01:28 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

This looks like it's supposed to work.

But does Vehicles.cs contain the Car class? What does it look like?

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
Reply With Quote
  #3 (permalink)  
Old January 12th, 2008, 05:40 PM
Registered User
Points: 33, Level: 1
Points: 33, Level: 1 Points: 33, Level: 1 Points: 33, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default



Code:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for Vehicles
/// </summary>
public class Vehicles
{
    protected int _wheels;
    protected int _topSpeed;
    protected string _warningSound;

    public int Wheels
    {
        get { return _wheels; }
        set { _wheels = value;}
    }

    public int TopSpeed
    {
        get { return _topSpeed; }
        set { _topSpeed = value; }
    }

    public virtual string Warning()
    {
        return _warningSound;
    }

    public Vehicles()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    public class Car : Vehicles
    {
        public Car()
        {
            _wheels = 4;
            _topSpeed = 150;
            _warningSound = "Honk";
        }
    }

    public class Bike : Vehicles
    {
        public Bike()
        {
            _wheels = 2;
            _topSpeed = 30;
            _warningSound = "Ring Ring";
        }
    }

    public class Skateboard : Vehicles
    {
        public Skateboard()
        {
            _wheels = 4;
            _topSpeed = 15;

        }
        public override string Warning()
        {
            return "No warning - you'll have to shout yourself";
        }
    }
}
Reply With Quote
  #4 (permalink)  
Old January 13th, 2008, 03:50 AM
Authorized User
 
Join Date: Sep 2007
Location: , , Finland.
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Don't declare Car class (or Bike and Skateboard classes) inside Vehicle class. What you should do is:

Code:
class Vehicle { ... }
class Car : Vehicle { ... }
class Bike : Vehicle { ... }
class Skateboard : Vehicle { ... }
You shouldn't declare nested classe unless there's a really good reason for it. And only good reason which comes to mind is a case where no other class uses nested class but the nesting class (in which case the nested class should be declared as private) and singletons.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Assembly Reference Problem jazzcatone ASP.NET 2.0 Basics 4 June 13th, 2007 11:38 PM
missing directive with simple datagrid pbarbalias ASP.NET 1.0 and 1.1 Basics 1 October 17th, 2006 07:48 PM
Bogus missing reference rahzan Access VBA 8 April 11th, 2005 08:35 AM
What missing reference rjp Access 4 December 7th, 2004 01:16 PM
IsBroken vs Missing Reference tlwaltz BOOK: Access 2003 VBA Programmer's Reference 1 August 5th, 2004 10:43 PM



All times are GMT -4. The time now is 03:57 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.