-5

If I create this piece of C# code:

using System;
public class Test
{
   private string x;
   public string GetX
   {
       get
       {
          return x;
       }
   }
}

What would the difference between the above and this:

using System;
public class Test
{
   private string x;
   public string GetX
   {
       return x;
   }
}
caconym
  • 167
  • 1
  • 9

2 Answers2

1

I assume you mean this for the second

using System;
public class Test
{
  private string x;
  public string GetX()
  {
    return x;
  }
}

In which case it is a method that returns a string while your first example is a readonly property

David Pilkington
  • 13,528
  • 3
  • 41
  • 73
0

Your second code snippet does not compile as it is neither a property nor a method.

we can not compare two un equal code snippets.

Sudhakar Tillapudi
  • 25,935
  • 5
  • 37
  • 67