How do i compile 2 C# source files together on win7

  • (2 Pages)
  • +
  • 1
  • 2

25 Replies - 4646 Views - Last Post: 05 August 2010 - 07:04 PM Rate Topic: -----

#1 dhkrullah  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 16-December 09

How do i compile 2 C# source files together on win7

Posted 03 June 2010 - 11:02 AM

Hi everyone or anyone http://http.cdnlayer...ult/biggrin.gif whenever i try compiln a program dt has 2 source files, a class dt has all other the methods and d 2nd class dt houses d main method what i get is ds error

GradeBookTest.cs(7,3): error CS0246: The type or namespace name 'GradeBook' could not be found (are you missing a using directive or an assembly reference?)
GradeBookTest.cs(7,25): error CS0246: The type or namespace name 'GradeBook' could not be found (are you missing a using directive or an assembly reference?)




meanwhile there in the same folder.

Is This A Good Question/Topic? 0
  • +

Replies To: How do i compile 2 C# source files together on win7

#2 elbielefeld  Icon User is offline

  • D.I.C Head

Reputation: 70
  • View blog
  • Posts: 216
  • Joined: 18-May 10

Re: How do i compile 2 C# source files together on win7

Posted 03 June 2010 - 11:09 AM

When you don't provide code, we can't tell you more then the compiler. A type or namespace "Gradebook" could not be found. Check your namespaces.
Namespace tutorial
Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,496
  • Joined: 23-August 08

Re: How do i compile 2 C# source files together on win7

Posted 03 June 2010 - 11:24 AM

2geder???? (together in the title was originally 2geder...I modified it to English)

Please use something approximating actual English in your posting. We are not a bunch of 14-year-old girls texting on our phones under the covers at night; this is a forum of professionals.

This post has been edited by JackOfAllTrades: 03 June 2010 - 12:16 PM
Reason for edit:: Explanation of 2geder

Was This Post Helpful? 3
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5481
  • View blog
  • Posts: 11,762
  • Joined: 02-June 10

Re: How do i compile 2 C# source files together on win7

Posted 03 June 2010 - 11:31 AM

Quote

Hi everyone or anyone http://http.cdnlayer...ult/biggrin.gif whenever i try compiln a program dt has 2 source files, a class dt has all other the methods and d 2nd class dt houses d main method what i get is ds error

It took a little while to translate your question. I hope this helps other readers:

Quote

Hi everyone. Whenever i try compiling a program that has 2 source files, a class that has all other the methods and a 2nd class that houses the main method what i get is this error.


The files being in the same folder isn't magical. Are they using the same namespace.

Namespace Yogi
{
   class One
   {
      public string Basket()
      {
         return "picnic";
      }
   }
}

Namespace Booboo
{
   class Two
   {
      public void Answer()
      {
        string Result = Basket();// Since class one is in a different namespace, we can't see it's methods from here
      }
   }
}


Without seeing the code where you define your GradeBook and the code where you try to use the GradeBook class, I can't help much more.
Was This Post Helpful? 2
  • +
  • -

#5 dhkrullah  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 16-December 09

Re: How do i compile 2 C# source files together on win7

Posted 07 June 2010 - 06:04 AM

Am sorry 4 postn like that. i was not using namespaces this the code


using System;

public class GradeBook
{
	private string courseName;
	private int[] grades;
	
	public GradeBook(string name, int[] gradesArray)
	{
		CourseName = name;
		grades = gradesArray;
	}
	
	public string CourseName
	{
		set
		{
			courseName = value;
		}
		get
		{
			return courseName;
		}
	}
	
	public void DispMessage()
	{
		Console.WriteLine("Welcome to the grade book for\n{0}!", CourseName);
	}
	
	public void ProcessGrades()
	{
		OutputGrades();
		
		Console.WriteLine("\nClass average is{0:F2}", GetAverage());
		
		Console.WriteLine("Lowest grade is {0}\nHighest grade is {1}", GetMinimum(), GetMaximum() );
		OutputBarChart();
	}
	
	public int GetMinimum()
	{
		int lowGrade = grades[0];
		foreach( int grade in grades )
		{
			if (grade < lowGrade)
				lowGrade = grade;
		}
		
		return lowGrade;
	}
	
	public int GetMaximum()
	{
		int highGrade = grades[0];
		
		foreach( int grade in grades)
		{
			if( grade > highGrade )
				highGrade = grade;
		}
		
		return highGrade;
	}
	
	public double GetAverage()
	{
		int total = 0;
		
		foreach( int grade in grades)
			total += grade;
			
		return (double) total / grades.Length;
	}
	
	public void OutputBarChart()
	{
		Console.WriteLine("Grade distribution: ");
		
		int[] freq = new int[11];
		
		foreach( int grade in grades )
			++freq[grade/10];
			
		for( int count = 0; count < freq.Length; count++)
		{
			if( count == 10 )
				Console.Write("   100: ");
			else
				Console.Write("{0:D2}-{1:D2}", count * 10, count * 10 + 9);
				
			for( int stars = 0; stars < freq[count]; stars++)
				Console.Write("*");
			Console.WriteLine();
		}
	}
	
	public void OutputGrades()
	{
		Console.WriteLine("The grades are:\n");
		
		for( int student = 0; student < grades.Length; student++)
			Console.WriteLine("Students {0, 2}: {1, 3}", student + 1, grades[student]);
	}
}




the class that houses the main method


public class GradeBookTest
{
	public static void Main(string []args)
	{
		int[] gradesArray = { 87, 68, 94, 100, 78, 85, 91, 76, 87};
		
		GradeBook objgb = new GradeBook("CS101 Intro to C#", gradesArray);
		
		objgb.DispMessage();
		objgb.ProcessGrades();
	}
}




thanks for answering even though my post was awful
Was This Post Helpful? 0
  • +
  • -

#6 Codey09  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 210
  • Joined: 20-August 09

Re: How do i compile 2 C# source files together on win7

Posted 07 June 2010 - 10:06 AM

I think you will find that they need to be in a namespace to work.

I've not written a piece of code yet that doesn't have a namespace.
Was This Post Helpful? 0
  • +
  • -

#7 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5481
  • View blog
  • Posts: 11,762
  • Joined: 02-June 10

Re: How do i compile 2 C# source files together on win7

Posted 07 June 2010 - 10:17 AM

Are you writting these files in Visual Studio... or Notepad?
They have none of the typical content that is added automatically by Visual Studio.
If you make a project, then add a class (like your GradeBook) it should have automatically created the namespace for you, as well as the right Using statements.

I think you need to start from scratch on a new project. If you have code from other sources, then add it to files that you create through Visual Studio so all the right pre-requites are added for you. Then you can paste your other code into the file; using it like a template.

You may also do a lot better if you follow some of the "My First Program" books and samples out there. Just to get your feet wet and gain some understanding of how the namespaces and classes relate to each other. *THEN* start the more complex tasks of combining several unrelated sources together.

Build a Program Now! in Visual C# by Microsoft Press, ISBN 0-7356-2542-5
is a terrific book that has you build a Windows Forms application, a WPF app, a database application, your own web browser.

Microsoft Visual Studio Tip, 251 ways to improve your productivity, Microsoft press, ISBN 0-7356-2640-5
Has many, many great, real-world tips that I use all the time.

MSDN C# Developers Center with tutorials
Welcome to Visual Studio

Have you seen the MSDN Code Samples? They spent a lot of time creating samples and demos. It seems a shame to not use them.

  • Anonymous Delegates: Demonstrates the use of unnamed delegates to reduce application complexity.
  • Arrays: Shows how to use arrays.
  • Attributes: Shows how to create custom attribute classes, use them in code, and query them through reflection.
  • Collection Classes: Shows how to make non-generic collection classes that can be used with the foreach statement.
  • COM Interop Part I: Shows how to use C# to interoperate with COM objects.
  • COM Interop Part II: Shows how to a use a C# server together with a C++ COM client.
  • Commandline: Demonstrates simple command-line processing and array indexing.
  • Condiational Methods: Demonstrates conditional methods, which provide a powerful mechanism by which calls to methods can be included or omitted depending on whether a symbol is defined.
  • Delegates: Shows how delegates are declared, mapped to static and instance methods, and combined into multicast delegates.
  • Events: Shows how to declare, invoke, and configure events in C#.
  • Explicit Interface: Demonstrates how to explicitly implement interface members and how to access those members from interface instances.
  • Generics: Shows how to make generic collection classes that can be used with the foreach statement.
  • Hello World: A Hello World application.
  • Indexers Part I: Shows how C# classes can declare indexers to provide array-like access to objects.
  • Indexers Part II: Shows how to implement a class that uses indexed properties. Indexed properties enable you to use a class that represents an array-like collection.
  • Libraries: Shows how to use compiler options to create a DLL from multiple source files; also, how to use the library in other programs
  • Named and Optional (C# 4.0): Demonstrates Named and Optional parameters, an alternative to method overloads
  • Nullable: Demonstrates value types, such as double and bool, that can be set to null
  • Office Sample (C# 4.0): Demonstrates how Dynamic and COM Interop make it easy to call Microsoft Office in C# 4.0
  • OLEDB: Demonstrates how to use a Microsoft Access database from C# by creating a dataset and adding tables to it.
  • Operator Overloading: Shows how user-defined classes can overload operators
  • Partial Types: Demonstrates how classes and structures can be defined in multiple C# source-code files
  • PInvoke: Shows how to call exported DLL functions from C#
  • Properties: Shows how properties are declared and used; also demonstrates abstract properties
  • Python Sample (C# 4.0): Learn how to call a Python script by using the Dynamic feature in C# 4.0
  • Security: Discusses .NET Framework security and shows how to modify security permissions in C# by using permission classes and permission attributes
  • Simple Variance (C# 4.0): See how Covariance and Contravariance are supported in generic interfaces and delegates
  • Structs: Shows how to use structs in C#.
  • Threading: Demonstrates various thread activities such as creating and executing a thread, synchronizing threads, interacting between threads, and using a thread pool
  • Unsafe: Shows how to use unmanaged code (code that uses pointers) in C#
  • User Conversions: Shows how to define conversions to and from user-defined types
  • Versioning: Demonstrates versioning in C# by using the override and new keywords
  • XML Documents: Shows how to document code by using XML
  • Yield: Demonstrates how to use the yield keyword to filter items in a collection

Was This Post Helpful? 1
  • +
  • -

#8 dhkrullah  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 16-December 09

Re: How do i compile 2 C# source files together on win7

Posted 08 June 2010 - 06:07 AM

am using notepad
Was This Post Helpful? 0
  • +
  • -

#9 dhkrullah  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 16-December 09

Re: How do i compile 2 C# source files together on win7

Posted 08 June 2010 - 06:13 AM

@#7 tlhIn'toq; thanks so much for mentioning MSDN.i couldnt install msdn on my visual studio 2008, i go through alot of stress try to understand some C# classes. any help in how to get it
Was This Post Helpful? 0
  • +
  • -

#10 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5481
  • View blog
  • Posts: 11,762
  • Joined: 02-June 10

Re: How do i compile 2 C# source files together on win7

Posted 08 June 2010 - 08:05 AM

If you have VS08 why are you writing code in Notepad.
You're just making life hard on yourself.
As recommended earlier... write your code in VS08 and let it do its job of stubbing out code files for you.
Was This Post Helpful? 1
  • +
  • -

#11 dhkrullah  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 16-December 09

Re: How do i compile 2 C# source files together on win7

Posted 08 June 2010 - 08:34 AM

i do use visual studio, the problem with visual studio is that in a project i cant have more than one source file that houses the main method.
Was This Post Helpful? 0
  • +
  • -

#12 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5481
  • View blog
  • Posts: 11,762
  • Joined: 02-June 10

Re: How do i compile 2 C# source files together on win7

Posted 08 June 2010 - 08:46 AM

That's not a Visual Studio limitation. That's the case for writing a program. Period. It doesn't matter what compiler you use, your program can only have one Main method.

tlhIn'toq:

Quote

You may also do a lot better if you follow some of the "My First Program" books and samples out there. Just to get your feet wet and gain some understanding of how the namespaces and classes relate to each other. *THEN* start the more complex tasks of combining several unrelated sources together.

Was This Post Helpful? 1
  • +
  • -

#13 dhkrullah  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 16-December 09

Re: How do i compile 2 C# source files together on win7

Posted 08 June 2010 - 08:51 AM

My Problem how do i compile two C# source file in the command prompt.

1 class has the methods and the constructor, the second class has the main method.
Was This Post Helpful? 0
  • +
  • -

#14 dhkrullah  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 16-December 09

Re: How do i compile 2 C# source files together on win7

Posted 08 June 2010 - 08:58 AM

am having only 1 Main method, its just like u dividing 1 thing into two, one does all the work the other tells it to start doing its job.
Was This Post Helpful? 0
  • +
  • -

#15 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5481
  • View blog
  • Posts: 11,762
  • Joined: 02-June 10

Re: How do i compile 2 C# source files together on win7

Posted 08 June 2010 - 09:03 AM

First you say you have two main methods. Then you say you have one. First you say you are using Visual Studio, then you say you want to compile using command line.

I'm going to bow out of this conversation now with one last repeat of my earlier advice. Build the project in Visual Studio. Just Visual Studio. Add your new classes inside the new project. If you have code from elsewhere then copy/paste *just the methods* into the classes you made within Visual Studio because you know those classes were made correctly and have all the pre-requisites you need.

You will never be able to take one complete project with its own main() and a totally separate project with its own main() and just magically merge them together and have them work.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2