CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    May 2011
    Posts
    27

    Error while trying to run the program.

    Hi,

    while running a simple class vehicle and another class vehiledemo will instantiates the vehicle object inside the vehicledemo class.But giving an error below.I have declared "using System;" at the starting of the program.I dont why i get this srror .any idea to solve ? because am novice in C#.

    Error:

    Error 1 'Vehicle' does not contain a definition for 'Console' and no extension method 'Console' accepting a first argument of type 'Vehicle' could be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\MYPC\My Documents\Visual Studio 2008\Projects\keerth123\keerth123\Vehicle.cs 18 9 keerth123.

    Thanks in advance!

  2. #2
    Join Date
    Jan 2010
    Posts
    1,133

    Re: Error while trying to run the program.

    Unless you've written something like
    myVehicle.Console.WriteLine( /* ... */ );
    the error seems rather unusual.
    How about you show us some code, or at least the line of code that causes the error?

  3. #3
    Join Date
    Dec 2008
    Location
    Step Into(F11)
    Posts
    465

    Thumbs up Re: Error while trying to run the program.

    and before posting a question . you ask form yourself .is this much information is sufficient to reply by other member ?.

  4. #4
    Join Date
    May 2011
    Posts
    27

    Re: Error while trying to run the program.

    This is the program am running in same VehicleDemo.CS

    using System;
    class Vehicle
    {
    public int Passengers;
    public int Fuelcap;
    public int Mpg;
    }
    class VehicleDemo
    {
    static void Main()
    {
    int Stranger = 2;
    Vehicle minivan = new Vehicle();
    minivan.Passengers = 7;
    minivan.Fuelcap = 56;
    minivan.Mpg = 44;
    int range = minivan.
    Console.WriteLine("strangers:" + Stranger + "range" + range);
    }
    }

    I could not just understand how to run this ....with out errors..I made separate codefiles for both vehicle and vehicledemo class uder same project...gives same kind of error.

  5. #5
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Error while trying to run the program.

    Write line expects a string you are starting with a string then adding an integer then a string then another integer.

    you should use the .ToString method to change those ints into strings for the purpose of printing them.

    And this line
    Code:
    int range = minivan.
    is not valid

    What you are actually doing is
    Code:
    int range = minivan.Console.WriteLine("strangers:" + Stranger + "range" + range);
    Which is invalid and resulting in your error
    Last edited by DataMiser; March 9th, 2012 at 12:01 AM.
    Always use [code][/code] tags when posting code.

  6. #6
    Join Date
    May 2011
    Posts
    27

    Re: Error while trying to run the program.

    Sorry..this is really silly mistake i made...I was trying to do..with out my notice was trying to compile not even realising that i didnt complete the line...thanks ..alot for giving solution for it.am novice in C#..so pls dont mine.now am able to compile and run the

    the below calculation....

    Code:
    int range = minivan.Fuelcap * minivan.Mpg;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured