我如何获得输出 [英] How do i get the output

查看:88
本文介绍了我如何获得输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是我的代码

Hi,

This is my code

public class Test : IPerl
    {
        public void Read()
        {
            Console.WriteLine("Read");
        }
    }







public interface IPerl
    {
        void Read();
    }




这另一个文件




This another file

static void Main()
        {
            IPerl perl = new Test();
            perl.Read();
        }



现在我想要以下一行



Now i want the out of the following line

perl.Read();



可能吗??我不知道该怎么办,我正在使用Visual Studio
请让我知道.

谢谢.



is it possible?? I don''t know how to and i am using Visual Studio
Please let me know .

Thanks.

推荐答案

如果您的目的是从Console 读取并将输入作为string返回,则在IPerl 界面中使用Read 方法可能会返回string 并且可能进行如下其他修改:
If your purpose is to read from Console and return the input as a string, then the Read method in IPerl interface may be made to return a string and other modifications may be made as follows:
using System;

namespace ReadFromConsole {
    class Program {
        static void Main(string[] args) {
            IPerl perl = new Test();
			Console.WriteLine (perl.Read());
            Console.ReadKey();
        }
    }
    public class Test : IPerl {
        public string Read() {
            var conkeyinfo = Console.ReadLine();
            return conkeyinfo.ToString();
        }
    }

    public interface IPerl {
        string Read();
    }
}


查看此链接,您将获得一些IDea
C#接口(面向初学者) [
See this link You Will Get Some IDea
Interfaces in C# (For Beginners)[^]


这篇关于我如何获得输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆