-6

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
  • 157
  • 2
  • 8

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,297
  • 3
  • 39
  • 67
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,307
  • 5
  • 35
  • 65