Today I had an interview, and I was asked if the code below is a good example / case of using reflection in C# :
public abstract class Level{ public string LevelID { get; private set;} public int LevelNumber { get{ return int.Parse(LevelID.Substring(5).ToString()); } } public Level(){ this.LevelID = GetType().ToString(); } }
I assume the use of the code above:
class Level32 : Level{
and then
Level32 level = new Level32(); int id = level.LevelNumber;
I think this guy meant this line: this.LevelID = GetType().ToString();
I said that there is no reflection at all.
As far as I know Java , calling SomeClass.class.getName() does not use any of the "reflective" packages, so it does not use reflection at all. I thought C# was built too.
Am I stupid or is he?
user6367252
source share