Splitting your C♯ Code into Multiple Files
I have just started to work out how to split my C♯ code into multiple files, and thought that I would share it with you. This post will be about what I believe to be static linking, but I could be wrong. Anyway, it is actually quite simple:
Here is the contents of filea.cs
:
using System;
class ClassA
{
public static void Main()
{
Console.WriteLine("This is a test from file A");
Someplace.ClassB.PrintHello();
}
}
and here is the contents of fileb.cs
:
using System;
namespace Someplace
{
class ClassB
{
public static void PrintHello()
{
Console.WriteLine("Another hello from file B!");
}
}
}
Then when you compile, you should do something like this:
csc filea.cs fileb.cs
This will tell the C Sharp compiler to grab both filea.cs
and fileb.cs
, and to output a single filea.exe
.
Next I will try to figure out how to create a .dll
file and include that - then I can build my own libraries.