'base' as function parameter name in C #

I am currently following the recommendations of the Microsoft Naming Guidelines, so using camelCase in function parameter names. Now suppose I would like to use a signature

public string WriteNumberInBase (int number, int base)

in some method, and the compiler complains about the parameter name only because "base" is a reserved keyword ... Is there a way to get a "base" to accept as a parameter name?

+3
source share
5 answers

Try the following:

public string WriteNumberInBase (int number, int @base)
//                                               ^
//                             the @ sign is used to "escape" keywords

(As an extra note in VB.NET, you will do the same by placing the keyword or reserved word in square brackets, for example [MyBase].)

, , radix base.

+16

@base, .

Convert.ToString(int, int), toBase .

radix ( ) . , , .

+4

.

public string WriteNumberInBase (int number, int @base)

@:

DoSomethingWith (@base);

, .
, , @ , , .

+3

"@", :

public string WriteNumberInBase(int number, int @base)
+1
source

use @base instead of the base .... it applies to all keywords ... use @ in front of the keyword and you'll be fine

0
source

Source: https://habr.com/ru/post/1794256/


All Articles