谁能一步一步解释下面的编码? [英] Can anyone explain the following coding step by step?

查看:83
本文介绍了谁能一步一步解释下面的编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以一步一步解释这个codin吗?

这是代码:

Can anyone explain this codin step by step?

Here is the coding :

using System;

delegate string StrMod(string str);

class MainClass {

  static string replaceSpaces(string a) {
    Console.WriteLine("replaceSpaces");
    return a;
  }

  static string removeSpaces(string a) {
    Console.WriteLine("removeSpaces");
    return a;
  }

  static string reverse(string a) {
    Console.WriteLine("reverseSpaces");
    return a;
  }

  public static void Main() {
    StrMod strOp = new StrMod(replaceSpaces);
    string str;

    str = strOp("This is a test.");

    strOp = new StrMod(removeSpaces);
    str = strOp("This is a test.");

    strOp = new StrMod(reverse);
    str = strOp("This is a test.");
  }
}

推荐答案

您知道逐行解释代码的工作量吗?
每一行都需要一段说明!例如:
Do you have any idea how much work explaining code line by line is?
Every single line needs a paragraph of explanation! For example:
int next = r.Next();


创建一个名为"next"的新变量,该变量可以容纳一个整数值.在先前声明的Random实例"r"中,调用"Next"方法以获取新的随机数,并将其分配给"next"变量.

您能想象我们需要花多长时间一行一行地解释一个非常短的代码片段吗?

不,这不会发生.如果您有特定的问题,请提出一个问题.但是首先考虑-您是否想坐下45分钟并无缘无故地逐行输入描述?


Create a new variable called "next" which can hold a integer value. From the previously declared Random instance "r", call the "Next" method to get a new random number, and assign it to the "next" variable.

Can you imagine how long it would take us to explain even a very short code fragment like your example, line by line?

No. It is not going to happen. If you have a specific problem, then ask a question about it. But think first - would you want to sit down for 45 minutes and type up a line-by-line description for no good reason?


我会给您一些想法,方法是将您指向您发布的代码片段中有趣的部分:

I''ll give you a couple of ideas by pointing you to the interesting parts in the code fragment you posted:

using System;
// Here a type is declared that is something akin to a pointer to
// a function that returns a string and takes a string as a parameter.
delegate string StrMod(string str);

class MainClass {

  // This is a function that returns a string and takes a string as a parameter
  // This function does not really replace spaces, but only writes output to the console and returns
  // the original string. 
  static string replaceSpaces(string a) {
    Console.WriteLine("replaceSpaces");
    return a;
  }

  // This is a function that returns a string and takes a string as a parameter
  // This function does not really remove spaces, but only writes output to the console and returns
  // the original string.
  static string removeSpaces(string a) {
    Console.WriteLine("removeSpaces");
    return a;
  }

  // This is a function that returns a string and takes a string as a parameter
  // This function does not really reverse a string, but only writes output to the console and
  // returns the original string.
  static string reverse(string a) {
    Console.WriteLine("reverseSpaces");
    return a;
  }

  public static void Main() {
    // After this line strOp can be called like a function that returns a string and takes a string as a parameter.
    // The dummy function replaceSpaces will be called.
    StrMod strOp = new StrMod(replaceSpaces); 
    string str;
    str = strOp("This is a test.");
    
    // After this line strOp can be called like a function that returns a string and takes a string as a parameter.
    // The dummy function removeSpaces will be called.
    strOp = new StrMod(removeSpaces);
    str = strOp("This is a test.");

    // After this line strOp can be called like a function that returns a string and takes a string as a parameter.
    // The dummy function reverse will be called.
    strOp = new StrMod(reverse);
    str = strOp("This is a test.");
  }
}



问候,

—MRB



Regards,

—MRB


我敢肯定这里有很多人,但是为什么会呢?
您没有试图解释您不了解其中的哪一部分,或者为什么需要这样做.

我对请帮我做功课"这个问题感到不解...
I''m sure many people here could, but why would they?
You''ve made no attempt to explain what part of it you don''t understand, or why you need to.

It smacks to me of a "Please do my homework for me" question...


这篇关于谁能一步一步解释下面的编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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