I want to create a new struct in C# that can do this:
// I can assign to the struct itself, just like a bool;
NewBool myBool;
myBool = true;
myBool; // Returns true
// I can assign to array elements underneath it using a string identifier
myBool["test"] = true;
myBool["test"] = false;
Question
Sn1p3t
I want to create a new struct in C# that can do this:
Currently, i've only been able to do this:
using System; public struct NewBool { ? ?public bool Value ? ?{ ? ? ? ?get { return false; } ? ? ? ?set { } ? ?} ? ?public bool this[string sourceID] ? ?{ ? ? ? ?get { return true; } ? ? ? ?set { } ? ?} }This code produces a struct that I can assign to array elements underneath it, but I can't assign directly to the struct. (myBool = true;).
Do I need to override the = operator?
EDIT: Just found out I can't override the assignment (=) operator. Now I'm really confused on how to do this.
Link to comment
Share on other sites
4 answers to this question
Recommended Posts