更改为方法声明 [英] Change to method declaration

查看:106
本文介绍了更改为方法声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做一个评估,这是我得到了一个问题:

I was doing an assessment and this is one of the questions I got:

以下哪些变化不能到C#方法调用的声明(进行 document.SaveAs(...))以下精简代码:

Which of the following changes cannot be made to the declaration of the C# method call(document.SaveAs(...)) below to streamline the code:

object fileName = "Test.docx";
object missing = Missing.Value;

document.SaveAs(ref fileName,
                ref missing,
                ref missing,
                ref missing,
                ref missing,
                ref missing,
                ref missing,
                ref missing,
                ref missing,
                ref missing,
                ref missing,
                ref missing,
                ref missing);




  • 替换对象缺少= Missing.Value; 对象缺少

  • 删除目标文件名=Test.docx; 语句

  • 删除 REF出现的所有

  • 替换 REF文件名文件名:Test.docx

  • 替换 REF文件名文件名:REF文件名

    • Replace object missing = Missing.Value; with object Missing
    • Remove object fileName = "Test.docx"; statement
    • Remove all occurences of ref
    • Replace ref fileName with FileName: "Test.docx"
    • Replace ref fileName with FileName: ref fileName.
    • 我已经做了评估,我只是好奇,因为我确实没有得到这个问题。

      I already did the assessment, I'm just curious because I actually did not get the question.

      感谢。

      更新

      我已经收到了效果与不幸刚好拿到89%,其中根据招聘人员是不够的...反正,就像我之前说的,我选择D和E的选择,并得到了部分问题的权利,因为我只能在最,选项A,B,C和D不能正确选择3个选项。

      I've receive the results and "unfortunately" got just 89% which according to the recruiter, is not enough... anyway, like I said before I choose options D and E, and got the question partially right, and given that I can only select 3 options at the most, options A, B, C and D can't be all correct.

      推荐答案

      作为最后一个是造成混乱,这可能帮助。

      As the last one is causing confusion, this might help.

      public class Document
      {
          public void SaveAs(ref string DocName)
          {
      
          }
      }
      

      注意参数的名字是可采用DocName 。通常这个参数名称被认为是唯一的东西所用的方法之外的方法和不重要的,但因为.NET 4.0(我认为),C#可以将旧命名此格式的参数。如果你熟悉Objective-C的话,你会经常看到这些。随着命名参数,可采用DocName 是很重要的。

      Notice the parameter name is DocName. Usually this parameter name is thought of as something only used by the method and unimportant outside the method, but since .NET 4 (I think?), C# can used named parameters in this format. If you're familiar with Objective-C then you'll see these often. With named parameters, DocName is important.

      我们现在可以调用这个方法类似这样

      We can now call this method like this

      string fName = "Test.docx";
      Document d = new Document();
      d.SaveAs(DocName: ref fName);
      



      注意可采用DocName 已被使用,否则编译器会抛出一个错误(所以你不能做 d.SaveAs(RandomName:REF FNAME); )。还要注意的是一个字符串变量传递和方法声明( d.SaveAs(可采用DocName:Test.docx); )内不能被实例化。

      Note that DocName has to be used, otherwise the compiler will thrown an error (so you couldn't do d.SaveAs(RandomName: ref fName);). Also note that a string variable is passed and not instantiated within the method declaration (d.SaveAs(DocName: "Test.docx");).

      这篇关于更改为方法声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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