小编Mat*_*est的帖子

为什么Console.WriteLine不能在Visual Studio代码中工作?

我在Visual Studio Code上安装了scriptcs和coderunner.当我运行一个简单的程序,包括Console.WriteLine("Test")我没有看到任何输出.该程序似乎成功运行并退出代码0.

有什么建议?

以下是所有人都感兴趣的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Test");
    }
}
Run Code Online (Sandbox Code Playgroud)

c# scriptcs visual-studio-code vscode-code-runner

10
推荐指数
2
解决办法
5503
查看次数

如何创建一个将泛型类作为参数的方法

我一直在搜索SO和其他地方寻找这个问题的答案,我找不到能帮助我理解我的问题的答案.我是C#的新手,所以这可能是问题的一部分.

我试图了解如何将一个类(或一个副本)作为参数传递给方法.但是,我希望这个方法接受我传递的任何类,而不是特定的类.

例如:

class Person
{
    public string Name{ get;set; }
}

class Bob : Person
{
    public Bob(){ Name = "Bob"; }
}

class Fred : Person
{
    public Fred(){ Name = "Fred"; }
}

Fred aFred = new Fred();
Bob aBob = new Bob();

// below is where I need the help, I don't know the syntax for what I'm trying to do.
SayName(aBob,aFred);

static public void SayName(person1,person2)
{
    Console.WriteLine(person1.Name + ", " +person2.Name) // I'd like this …
Run Code Online (Sandbox Code Playgroud)

c#

2
推荐指数
1
解决办法
126
查看次数