我已经为C#的控制台应用程序启动了Visual Studio项目。
我已经开始了该项目,通常在改进程序时保存进度。
我通常会保存CS文件,例如FILE1a.cs,FILE1b.cs和FILE1c.cs。
问题是,当我按F5键调试程序时,Visual Studio始终默认调试为FILE1a.cs。
如何使Visual Studio调试或运行其他CS文件?
这就是版本控制系统的用途,否则您将得到“ FILE1-final.cs”,“ FILE1-final2.cs”,“ FILE1-reallyfinal.cs”等。将您的代码保存在一个文件中,并使用一个记录该文件编辑历史记录的系统。
当前,Git流行并且正在发生,替代品是Mercurial和Team Foundation Server。
话虽这么说,您在一个项目中只能有一个启动方法,并且每次要测试代码时都必须更改此启动方法。
如果您正在尝试一个类的不同实现,则只需实例化适当的类。
您可以让这些实现实现一个接口,以便可以通过一个变量引用它们:
public class Program
{
public static void Main()
{
IImplementation implementation = new Impl1();
//IImplementation implementation = new Impl2();
//IImplementation implementation = new Impl3();
Console.WriteLine(implementation.Foo());
}
}
public interface IImplementation
{
string Foo();
}
public class Impl1 : IImplementation
{
public string Foo()
{
return "Foo";
}
}
public class Impl2 : IImplementation
{
public string Foo()
{
return "F" + "o" + "o";
}
}
public class Impl3 : IImplementation
{
public string Foo()
{
return string.Concat("F", "o", "o");
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句