Jump to content

Compiling Error

- - - - -

  • Please log in to reply
5 replies to this topic

#1
Howdy_McGee

Howdy_McGee

    Programmer

  • Members
  • PipPipPipPip
  • 135 posts
Ok, So i'm making a class and a driver both in the same folder, the class is:


namespace students

{

class Student

{

private int idNumber;

private string lastName;

private double gradePointAverage;

public const double HIGHEST = 4.0;

public const double LOWEST = 0.0;


public int IdNumber

{

get

{

return idNumber;

}

set

{

idNumber = value;

}

}


public string LastName

{

get

{

return lastName;

}

set

{

lastName = value;

}

}


public double GradePointAverage

{

get

{

return gradePointAverage;

}

set

{

if(value >= LOWEST && value <= HIGHEST)

{

gradePointAverage = value;

}

else

{

gradePointAverage = LOWEST;

}

}

}

}

}


and the driver looks like this:


using System;


namespace students

{

	public class CreatingStudents

	{

		public static void Main()

		{

			Student first = new Student();

			Student second = new Student();

			first.IdNumber = 123;

			first.LastName = "Anderson";

			first.GradePointAverage = 3.5;

			second.IdNumber = 789;

			second.LastName = "Daniels";

			second.GradePointAverage = 4.1;

			

			Display(first);

			Display(second);

		}

		

		public static void Display(Student stu)

		{

			Console.WriteLine("{0,5}{1,-10}{2,6}",

					stu.IdNumber, stu.LastName, stu.GradePointAverage.ToString("F1"));

		}

	}

}


I can't compile the CreatingStudents class without compiling the Students class first, but when I try to compile "csc Student.cs" I get this error:

Quote

'directory/Student.exe' does not contain a static 'Main' method suitable for an entry point.

Any help"?

#2
dbug

dbug

    Programmer

  • Members
  • PipPipPipPip
  • 155 posts
Maybe you need to compile both files at once (csc Student.cs CreateStudent.cs) or compile Student.cs as a library or module instead of a standalone executable (/taget:library or /target:module). See the help of csc to get more options (csc /?).

Another possibility is to use the Visual Studio IDE. It will handle all this things automatically.

#3
cdg10620

cdg10620

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 389 posts
I would use visual studio. You can get the express version here: Microsoft Visual Studio Express - Build cutting edge Windows applications
-CDG10620
Software Developer

#4
Howdy_McGee

Howdy_McGee

    Programmer

  • Members
  • PipPipPipPip
  • 135 posts
Well i put it into visual studio and it works fine, the question is why? Why can't I run it from command prompt and use notepad ++???

#5
dbug

dbug

    Programmer

  • Members
  • PipPipPipPip
  • 155 posts
Because all the files of a project are not independent and when you compile them you cannot use separate commands (in general).

You can create a project with Visual Studio and then use MSBuild <project name>.sln to build it from command line. However, if you add or remove files you will need to use Visual Studio again (or manually edit the .sln or .csproj files).

When you run MSBuild, you will see the actual commands used to compile your project. This might help you in figuring out how to use csc manually.

#6
gokuajmes

gokuajmes

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 518 posts
you are probably new to C# or OOP but good you have setup your program this far. Your code arrangement is a bit a messed up i could give you the working code but that would make your brain work less , so here is the link to a good C# site
http://www.functionx.com/vcsharp/index.htm





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users