【发布时间】:2021-09-25 09:45:39
【问题描述】:
如何通过模板模板在 Sprite 中设置 id
public class templa<T> where T : class , new(){
public T CreateMe(){
T temp = new T();
shortInt si
si.Set(2, 2);
//T needs to have id as shortInt else it won't work
temp.id = si; // temp = si// doesn't work either
return temp;
}
}
public struct shortInt{
public short s;
public int i;
public void Set(short s, int i){
this.s = s;
this.i = i;
}
}
这里的 Sprite 有 id 这是我试图通过模板更改 id 来实现的目标
public class Sprite{
public Sprite(){}
public shortInt id;
set{
id = value;
}
}
我在网上搜索,发现只能用 { get;放; } 我在这里一无所知
【问题讨论】:
-
stackoverflow.com/questions/61297919/… 回答你的问题了吗?
-
没有答案回答了我的问题,您的 hiperlink 回答了新的 T()