c# - Create a property name with the same name as a Keyword -


this question has answer here:

i'm sure question has been asked before, can't find answer need.

i creating assembly using c# , 1 of it's structs named need. i'm trying following:

internal struct need {     internal need how     {                 {             return how;         }     }     internal need true     {                 {             return true;         }     } } 

i want create new property named true. need.true obvious ide doesn't trying create property has same name keyword.

the obvious fix change name else, truth, heart tells me that's not should do.

this peaked interest. can theoretically created variable (or whatever) , assembly should able figure out variable referring based on context , scope. if like: (pseudo code)

create int number create need.int number 

or if did like:

create int number // in want struct create int number // in need struct 

there should no issue assembly determine type wanted create based on context or scope. issue ide doesn't seem use correct scope , won't let me build.

i've tried, true, need.true, this.true, etc. no avail.

i'm sure having assembly determine "true" within it's "need" struct imperative it's functionality, assembly needs able use it's own type of true within scope , context, not ever language, or whatever specifies it, has specified be.

how this?

p.s. reason these properties make them read only. bonus points if can tell me way have them in internal struct , read only...

you can prefix @ before keyword.

internal struct need {     // btw properties result in infinit loop     internal need how     {                 {             return how;         }     }     internal need @true     {                 {             return @true;         }     } } 

edit:

if need return true property have implement implicit operator need(bool) :

internal struct need {     internal need @true     {         { return true; }     }      public static implicit operator need(bool value)     {         // todo: initialize         return new need();     } } 

or, change return type :

internal bool @true { { return true; } } 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -