C# автоматически заполняет значения общих ограничений ⇐ C#
-
Гость
C# автоматически заполняет значения общих ограничений
I am writing generic unlockable elements for my game and I needed two similar classes with generic. I have used struct LevelBased where U : LevelUnlockable and expected C# to understand it without writing T value on LevelUnlockable.
When I am creating the type I am writing as LevelBased but since I will use int[] as T parameter, I thought it is okay to write like this LevelBased but if I do this, visual studio throws error.
Do I need to fill both T parameters, is there another way?
My current struct:
public struct LevelBased where U : LevelUnlockable { public U[] unlockables; public enum LevelBasedType { Clamp, Repeat } public LevelBasedType overshootBehaviour; } I have tried moving T parameter somewhere else but with no avail. I am expecting to write this LevelBased as LevelBased this.
Источник: https://stackoverflow.com/questions/781 ... nts-values
I am writing generic unlockable elements for my game and I needed two similar classes with generic. I have used struct LevelBased where U : LevelUnlockable and expected C# to understand it without writing T value on LevelUnlockable.
When I am creating the type I am writing as LevelBased but since I will use int[] as T parameter, I thought it is okay to write like this LevelBased but if I do this, visual studio throws error.
Do I need to fill both T parameters, is there another way?
My current struct:
public struct LevelBased where U : LevelUnlockable { public U[] unlockables; public enum LevelBasedType { Clamp, Repeat } public LevelBasedType overshootBehaviour; } I have tried moving T parameter somewhere else but with no avail. I am expecting to write this LevelBased as LevelBased this.
Источник: https://stackoverflow.com/questions/781 ... nts-values
Мобильная версия