Why should I specify the keyword "out" in C #?

Before asking your question, please take a look at this function:

DateTime.TryParse("01/01/2000", out oDate)

Why specify a keyword out? Doesn't the compiler know about this from the function definition?

I ask for this out of sheer curiosity in the hope that I will learn something new about the compiler.

I should also clarify what I'm asking about the C # .NET 3.5 compiler in particular.

+3
source share
6 answers

The out keyword may be implied by the compiler, but I understand that the C # team decided to make the keyword outexplicitly required by the calling function to increase visibility regarding the nature of the parameter.

+17

, . , , .

+10

, , , , X.

++, . ++ , . , ++, .

+6

, , , , .

# , , , . :

  • switch .
  • if: if (x = 5) true.
+2

http://msdn.microsoft.com/en-us/library/t3c3bfhx(VS.80).aspx

" out , . ref, , ref , . out, , out."

DateTime.TryParse oDate, out.

+1

, #, , , -, , ?

#: . , , . , , .

, oDate , , , , .

: . # , , . , , TryParse(), . , . , , . ( , , out TryParse().)

, "" . , , , . .

0

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


All Articles