Console.WriteLine在Resolve()之后不起作用 [英] Console.WriteLine is not working after Resolve()

查看:96
本文介绍了Console.WriteLine在Resolve()之后不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码在执行期间不给出错误或警告。但是它忽略了console.read()函数,我是温莎的新手。

This code gives no error or warning during execution. but it ignores the console.read() function, i am newer with windsor. is it really a bug or the simple behavior of windsor ?

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();          
    }
}

}

推荐答案

我认为您可能要使用 Console.ReadLine 而不是 Console.Read

I think you probably want to use Console.ReadLine rather than Console.Read.

尝试以下代码片段以了解Read / ReadLine行为:

Try this snippet of code to understand Read/ReadLine behavior:

var a = Console.Read();
Console.WriteLine(a);
var b = Console.ReadLine();            
Console.WriteLine(b);

这篇关于Console.WriteLine在Resolve()之后不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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