Should a property have the same name as its type?

后端 未结 9 948
醉梦人生
醉梦人生 2020-12-01 06:06

I\'ve sometimes seen code written like this :

public class B1
{
}

public class B2
{
    private B1 b1;

    public B1 B1
    {
        get { return b1; }
           


        
9条回答
  •  生来不讨喜
    2020-12-01 06:31

    It can obviously be a bit confusing when the name of a property and it's type are the same, but other than that it's not really a problem.

    If the name makes sense, it's usually better to let the name and the type be the same. If you can think of a better name, you should of course use that, but you should not try to make up a name at any cost just to avoid this situation.

提交回复
热议问题