是新的C#,所以我真的不知道該怎麼做,但在C++中我是這樣做這樣不能鍵入「字節」轉換爲「T」
template <typename T> writeInt(int location, T value){
*(T*)&buffer[location] = value;
}
在C#中我試圖做同樣
public void WriteInt<T>(int location,T value)
{
(T)buffer[location] = value;
}
但我歌廳這個錯誤Cannot convert type 'byte' to 'T'
,所以我怎麼能做到這一點,得益於
你想做什麼?什麼是'T'?什麼是'buffer []'?看起來您可能需要堅持使用C++或重新調整C#中正常的視圖! – 2011-06-13 18:32:50
@David Heffernan所以我可以說WriteInt或32 etc,buffer = byte [] –
Abanoub
2011-06-13 18:34:09
你看過C#中的泛型(http://msdn.microsoft.com/en-us/library/ms379564(VS)。 80)的.aspx)? – yasouser 2011-06-13 18:34:52