-
March 7th, 2012, 05:09 AM
#1
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!
-
March 8th, 2012, 11:09 AM
#2
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?
-
March 8th, 2012, 05:33 PM
#3
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 ?.
-
March 8th, 2012, 10:24 PM
#4
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.
-
March 8th, 2012, 11:59 PM
#5
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.
-
March 9th, 2012, 03:07 AM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|