0

此代码在执行期间没有给出错误或警告。但它忽略了 console.read() 函数,我是温莎的新手。这真的是一个错误还是温莎的简单行为?

using System;
using Castle.Windsor;
using Castle.MicroKernel.Registration;

namespace CastleProject
{
class Program
{
    internal interface ILogger
    {
        void log(string message);
        void showMethod();
    }
    internal interface Ishowing
    {
        void checkInterface();
    }

    class Logger : ILogger
    {
        public void log(string message)
        {
            Console.WriteLine(message);
            Console.Read();
        }
        public void showMethod()
        {
            Console.WriteLine("This is again showing just function i existing");
        }

    }
    class Showing : Ishowing
    {
        public void checkInterface()
        {
            Console.WriteLine("this is line from checkInterface()");
            var a = Console.ReadLine();
            Console.WriteLine(a);
        }
    }

    static void Main(string[] args)
    {
        var container = new WindsorContainer();
        container.Register(Component.For<ILogger>().ImplementedBy<Logger>(),Component.For<Ishowing>().ImplementedBy<Showing>());
        var logger = container.Resolve<ILogger>();
        var logger2 = container.Resolve<Ishowing>();
        logger.log("hello message");
        logger.showMethod();
        logger2.checkInterface();          
    }
}

}

4

1 回答 1

1

我想你可能想要使用Console.ReadLine而不是Console.Read.

试试这段代码来理解 Read/ReadLine 行为:

var a = Console.Read();
Console.WriteLine(a);
var b = Console.ReadLine();            
Console.WriteLine(b);
于 2013-02-03T05:34:28.287 回答