Writing source code in seperate files
-
How can we write the long source of a program in 2 or 3 files and relate them together at build time.
Use Partial Classes[^].
Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
-
How can we write the long source of a program in 2 or 3 files and relate them together at build time.
If you referring to writing classes with an extensive amount of code. Then I'd suggest you use the "partial" key word. That way you can spread your class over separate files. In each file you just call the full declaration of the class but with the partial key word. Eg;
public partial class Employee
{
public void DoWork()
{
}
}public partial class Employee
{
public void GoToLunch()
{
}
}http://msdn.microsoft.com/en-us/library/wa80x488%28v=vs.80%29.aspx[^]
-
Use Partial Classes[^].
Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
-
I rather think he has five source-files (.cs) that should be linked to a single executable. The IDE does that for us :)
Bastard Programmer from Hell :suss:
The question (as with so many) is somewhat open to interpretation. :(
Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
-
How can we write the long source of a program in 2 or 3 files and relate them together at build time.
faraz34 wrote:
How can we write the long source of a program in
2 or 3 files and relate them together at build time.1. Design your application so that you can break the functionality into classes. Classes normally are rather small. This step has nothing to do with actually writing code. 2. Implement each class in a different file. 3. In C# you put all of the classes in a project which is then managed via a solution.
-
The question (as with so many) is somewhat open to interpretation. :(
Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
-
Yes, but the wording "two or three files" are a give-away. ..with everybody recommending on how to distribute classes over multiple files :D
Bastard Programmer from Hell :suss:
Which is why I made the suggestion that I did.
Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
-
How can we write the long source of a program in 2 or 3 files and relate them together at build time.
-
How can we write the long source of a program in 2 or 3 files and relate them together at build time.
In addition to using *.cs you can also put the specific files:
csc MyFirstClass.cs MySecondClass.cs etc.cs
The name of the first will be used to name the output (i.e. MyFirstClass.exe in this case) unless you specify a /out: target. IDEs generally hide this away from you – are you writing code in a text editor? You don't normally need to do that, as there are good free IDEs available for .Net.
-
faraz34 wrote:
How can we write the long source of a program in
2 or 3 files and relate them together at build time.1. Design your application so that you can break the functionality into classes. Classes normally are rather small. This step has nothing to do with actually writing code. 2. Implement each class in a different file. 3. In C# you put all of the classes in a project which is then managed via a solution.
jschell wrote:
3. In C# you put all of the classes in a project which is then managed via a solution.
You mean "in Visual Studio"; C# neither knows nor cares about projects and solutions.
-
Yes, but I use
/recurse:"*.cs"
-
Which is why I made the suggestion that I did.
Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
better way is to ask for more information about the question.!!! @faraz34 : what exactly you would like to achieve ? whats your problem ? thanks -Amit.
-
better way is to ask for more information about the question.!!! @faraz34 : what exactly you would like to achieve ? whats your problem ? thanks -Amit.
Not at all; I gave an answer which may be the right one. If not then OP can respond with more details.
Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
-
better way is to ask for more information about the question.!!! @faraz34 : what exactly you would like to achieve ? whats your problem ? thanks -Amit.
the ways of an MVP, you should treat with the greatest respect! :)
Luc Pattyn [My Articles] Nil Volentibus Arduum
Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.