For illustration, I've an enum class Genre with different enum fields and ToString() method will produce different results under different scenarios.
For examples,
Case 1:
public enum Genre {
A1 = 1, // .ToString() produces "A2"
A2 = A1, // .ToString() produces "A2"
B1 = 2, // .ToString() produces "B1" (Why not "B2"?)
B2 = B1 // .ToString() produces "B1" (Why not "B2"?)
}
Case 2:
public enum Genre {
A1 = 1, // .ToString() produces "A2"
A2 = A1, // .ToString() produces "A2"
B1 = 2 // .ToString() produces "B1"
}
Case 3:
public enum Genre {
A1 = 1, // .ToString() produces "A1" (Why not "A2"?)
A2 = A1 // .ToString() produces "A1" (Why not "A2"?)
}
Below are the experiment screenshots that I had done via Rider's Immediate Window. Another workaround is to use nameof()
but major places in our code base are using ToString()
and we do not want to change them.