0

I was wondering what is more efficient or the best practice for returning attributes of private members. For example:

class Foo
{
  private List<int> fooList;
  public Foo()
  {
    Random random = new Random();
    fooList = new List<int>(random.Next(1, 100));
  }
  // 
  public int Count { get { return fooList.Count; } }
  // or
  public int Count() { return fooList.Count; }
}

Which is best if I do not want to give public access to my list?

sfanjoy
  • 640
  • 6
  • 16

1 Answers1

0

Based on your example, you should stay with a property. Because the fooList.Count is a property.

samtrion
  • 111
  • 6