I saw this answer from this link Adding parameters to custom attributes of how is to add parameters on Custom Attribute
class MyCustomAttribute : Attribute {
public int[] Values { get; set; }
public MyCustomAttribute(params int[] values) {
this.Values = values;
}
}
[MyCustomAttribute(3, 4, 5)]
class MyClass { }
Now I am wondering if can't it be write like this?
class MyCustomAttribute : Attribute {
private int[] _values;
public MyCustomAttribute(params int[] values) {
_values = values;
}
}
[MyCustomAttribute(3, 4, 5)]
class MyClass { }
I changed the property Values into a variable _values. I also made it private and it works fine when I tried it.
Can someone enlighten me why the accepted answer is valid?