小编Boj*_*jje的帖子

为什么这个方法不需要参数?

我正在为一家公司的论文工作项目工作,我在理解一些代码方面遇到了一些困难.

在他们的代码中,他们有这样的一行

_subscriber.StartSubscribing(_messageHandler.HandleMessage);
Run Code Online (Sandbox Code Playgroud)

_subscriber函数在哪里定义

public override void StartSubscribing(Action<QueueItem> messageHandlerMethod);
Run Code Online (Sandbox Code Playgroud)

_messageHandler定义

public void HandleMessage(QueueItem message)
{
  //Do code here
}
Run Code Online (Sandbox Code Playgroud)

为什么在messageHandler顶部不需要HandleMessage的参数?

EI

_subscriber.StartSubscribing(_messageHandler.HandleMessage(QueueItem));
Run Code Online (Sandbox Code Playgroud)

c# delegates action

0
推荐指数
1
解决办法
76
查看次数

为什么我的foreach打印2个char?

我正在尝试为教育创建一个加密(ceasar),由于某些原因我似乎无法理解为什么我的简单代码(到目前为止)正在制造这样一个hazzle

static void Main(string[] args)
    {
        string word;
        int key = 0;
        Console.WriteLine("Write your messages");
        word = Console.ReadLine();
        Console.WriteLine("Enter your key cypher");
        key =int.Parse(Console.ReadLine());
        encrypt(word, key);
    }

    static void encrypt(string message, int key)
    {
        foreach (char otherword in message)
        {
            Console.Write(otherword);
            Console.Read();
        }
    }
Run Code Online (Sandbox Code Playgroud)

如果我在"编写你的消息"之后编写测试,然后将它放入我的string word并在我的函数中使用它encrypt,它应该输出

t 
e
s
t
Run Code Online (Sandbox Code Playgroud)

但是无论出于什么原因,我得到这样的输出

t
es
t
Run Code Online (Sandbox Code Playgroud)

而且我不明白为什么.

c# foreach output

-1
推荐指数
1
解决办法
77
查看次数

标签 统计

c# ×2

action ×1

delegates ×1

foreach ×1

output ×1