简体   繁体   English

C#字符串中的语法[/]是什么意思

[英]What is does the syntax [/ ] mean in a C# string

I am not able to google for as, as Google blocks out symbols. 由于Google会屏蔽符号,因此我无法通过Google搜索。

it appeared in this context: 它出现在这种情况下:

Console.WriteLine("Usage: findduplicatefiles [/sub] DirectoryName [DirectoryName]...");

Thanks :) 谢谢 :)

It doesn't mean anything in C#. 在C#中并不意味着任何东西。 All that Console.WriteLine() call does is write this string: Console.WriteLine()调用所做的只是编写以下字符串:

"Usage: findduplicatefiles [/sub] DirectoryName [DirectoryName]..."

into the console as output. 进入控制台作为输出。

However, in the Windows command line, / functions as a command-line argument delimiter, and [] means it's an optional argument. 但是,在Windows命令行中, /用作命令行参数定界符, []表示它是可选参数。 The usage prompt is telling the user that sub is an optional argument to use with the findduplicatefiles program. 使用提示告诉用户sub是与findduplicatefiles程序一起使用的可选参数。

Examples: 例子:

  • Run findduplicatefiles.exe against the current directory: 针对当前目录运行findduplicatefiles.exe

     C:\\>findduplicatefiles . 
  • Run findduplicatefiles.exe against the current directory with the sub argument: 使用sub参数对当前目录运行findduplicatefiles.exe

     C:\\>findduplicatefiles /sub . 
  • Run findduplicatefiles.exe against two directories, C:\\abc and C:\\def , with the sub argument: 对两个目录C:\\abcC:\\def带有sub参数的findduplicatefiles.exe

     C:\\>findduplicatefiles /sub abc def 

In this case is does not mean anything to C#. 在这种情况下,C#并不意味着任何东西。 It's just a character in the string just like the rest of the string. 与字符串的其余部分一样,它只是字符串中的一个字符。

"[/" in a string doesn't mean anything to C#. 字符串中的“ [/”对C#而言没有任何意义。 It just writes those characters out. 它只是将那些字符写出来。 But I think you are confused about the meaning of what is being written out. 但是我认为您对所写内容的含义感到困惑。

There is a convention when documenting command-line programs where putting an argument in square braces means the argument is optional. 在记录命令行程序时有一个约定,其中将参数放在方括号中表示该参数是可选的。 Thus, the string your program is writing out indicates that the command findduplicatefiles may optionally have an argument /sub after which it must have at least one directory name, and may optionally have other directory names. 因此,程序正在写出的字符串表示命令findduplicatefiles可以有一个可选的参数/sub ,其后必须至少具有一个目录名,并且还可以可选地具有其他目录名。

Means optionally put /sub before directoryName. 意味着可以选择将/sub放在directoryName之前。 It is not a C# question. 这不是一个C#问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM