c#中的Console.WriteLine方法不是写入其参数,而是来自另一个类的参数

时间:2014-07-15 08:51:43

标签: c# console.writeline

我使用的是Visual Studio 2013.我已经创建了一个空白的解决方案,我有两个不同的项目:" HelloCSharp"和" PrintMyName"。在第一个项目中,有一个包含以下源代码的类:

命名空间HelloCSharp {

class HelloCSharp
{
    static void Main(string[] args)
    {
        System.Console.WriteLine("Hello, C#!");
    }
}

}

在" PrintMyName" project中有一个包含以下源代码的类:

namespace PrintMyName
{

class PrintMyName
{
    static void Main(string[] args)
    {
        System.Console.WriteLine("Rosen");
    }
}
}

当我尝试运行这个程序时,该方法并没有写出参数" Rosen"但来自另一个班的论证"你好,C#!"。

我尝试使用替代代码,但结果是相同的(" Hello,C#!"):

namespace PrintMyName
{
class PrintMyName
{

    static void Main(string[] args)
    {
        String myFirstName = "Rosen";
        System.Console.WriteLine(myFirstName);
    }
}
}

如果有人知道这个问题的原因是什么以及如何打印我的名字,请给我一个答案! 谢谢!

1 个答案:

答案 0 :(得分:3)

您可能没有运行您认为正在运行的程序。检查是否在Visual Studio中将正确的项目设置为启动项目。

要更改它,请右键单击要运行的项目,然后查找Set Start Up Project(带齿轮符号)。