-2

I'm using Visual Studio 2017

I have a model called Request, in that model I have a property:

 public string Action { get; set; } 

now when I instantiate the class I can't access the property for the reason it directs me to

public delegate void Action()

enter image description here

I know it's wrong to make that kind of properties but I can't change it.

nvoigt
  • 75,013
  • 26
  • 93
  • 142
Michael meshaev
  • 31
  • 1
  • 11
  • 2
    Why the weirdly scribbled on image? Where is `public delegate void Action()` defined? – Liam Jan 14 '19 at 10:37
  • 7
    It is not wrong to make these properties and the compiler can handle it. Just write `Action = "value",`. – Sefe Jan 14 '19 at 10:37
  • 1
    Please edit your question and include your actual code and not an image of your code. – Linda Lawton - DaImTo Jan 14 '19 at 10:40
  • This code is invalid and you have red underline from intellisense. All the rest (*"I can't access the property"* and *" it directs me to ..."*) seems to be simply thoughts. It's highlighted, because intellisense at that point is not yet able to determine what this will be property and probably the easier *match* is to the type. But this is not a problem, nor the bug. – Sinatr Jan 14 '19 at 10:51

2 Answers2

1

Well, you haven't typed out the correct code yet, so the compiler tries to make sense of what you did type. Do it right and it will work:

Request = new Request
{
    // other fields...

    Action = "Text"
}
nvoigt
  • 75,013
  • 26
  • 93
  • 142
0

So, you're in the situation where the field name is the same as a pre-defined class name or a language clause or etc. It's not a problem if you use so called "verbatim" names format (a name preceded with @ symbol).

Request = new Request
{
    // other fields...

    @Action = "Text"
}

That way, you can have such field names as @var, @params, @yield and so on. Take a look here as an example: https://stackoverflow.com/a/92045/1964969

Yury Schkatula
  • 5,291
  • 2
  • 18
  • 42