简体   繁体   中英

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

I am not able to google for as, as Google blocks out symbols.

it appeared in this context:

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

Thanks :)

It doesn't mean anything in C#. All that Console.WriteLine() call does is write this string:

"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. The usage prompt is telling the user that sub is an optional argument to use with the findduplicatefiles program.

Examples:

  • Run findduplicatefiles.exe against the current directory:

     C:\\>findduplicatefiles . 
  • Run findduplicatefiles.exe against the current directory with the sub argument:

     C:\\>findduplicatefiles /sub . 
  • Run findduplicatefiles.exe against two directories, C:\\abc and C:\\def , with the sub argument:

     C:\\>findduplicatefiles /sub abc def 

In this case is does not mean anything to 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#. 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.

Means optionally put /sub before directoryName. It is not a C# question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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