Can method names begin with Get in.NET?

I came across a recent audit report in our company for the code that we support, which says that we should not use Get in a method (not a property) called GetSearchResults or GetXyzInformation. I looked at MS Recommendations ( http://msdn.microsoft.com/en-us/library/4df752aw(VS.71).aspx ) for the name of the method and according to the fact that Get is allowed, so what you think about it, can we have it or not from a standard point of view, if not why?

Additional information
I am adding more information after the first set of answers, the methods that I have in mind are the kind that is associated with interacting with the database, so the properties of the properties are not ideal.

+3
source share
8 answers

This is completely legal (it’s even legal to write get_Foo form methods that will encounter a synthesized compiler get method if you have to declare a Foo property using getter).

As for the good :

  • , , , , ,
  • , , , , .
  • "" -, .

, , , "", "", , , . p >

+8

, , , - API (, Delegate.GetInvocationList).

, , , GetFoo.

+13

, , , ( ).

:

, " ", :

public string TextWriter { get {...} set {...}}
public string GetTextWriter(int value) {...}
+9

Get-method , , .

, SearchResults { get; }

, , VB.NET:

ReadOnly Property Foo(ByVal i As Integer, ByVal j As Integer) As String
  Get
    Return ""
  End Get
End Property

, IL GetFoo(int, int), VB.NET - !

+3

, GetXyz, , ( , Xyz).

GetXyz FindXyz , null . , , , find null, .

+2

Get . , :

Get:

public string GetSomeString()
{
     return _someMemberVariable;
}

: , , , Get , .

.

public string GetSomeString()
{
     //Some code that does processing or includes logic.
}

, " " ( , ).

+1

- , / , , . - , , , - , , Get.

, - , - .

+1

Get , .

0

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


All Articles