Program.cs is my main file and main method within is the entry point for my application. I have 2 other files, file1.cs and file2.cs .Both classes have its own string that I want to output using the Console.WriteLine function. When I run the program.cs file the output from the 2 other files dont show. If I run the code separately adding static void Main(string[] args) then it works.
I tried changing the name of the methods as well but no success. I also tried importing the namespaces in the program.cs file.
using File1;
using File2;
Can anyone provide some guidance or docs that could help me?Thanks
Program.cs
using System;
namespace MyConsole
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Welcome User");
}
}
}
file1.cs
namespace File1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("This is string 1");
}
}
}
file2.cs
namespace File2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("This is string 2");
}
}
}
You have to call the methods from program.cs
ro be able to run those. Something like this:
using System;
namespace MyConsole
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Welcome User");
File1.Program.Main(args);
File2.Program.Main(args);
}
}
}
And you should make Program
class as static too on File1 and File2
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.