Würde auch gehen, dann muss man aber eine Klassenbeschränkung für T angeben
[cs]using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TryOutProject
{
class genericSampleClass
{
public string readString(){
return "";
}
public int readInt(){
return 0;
}
public bool readBoolean(){
return true;
}
public byte readByte()
{
return 0;
}
public T read<T>() where T : class
{
switch(typeof(T).FullName.ToUpper())
{
case ("BYTE"):
{
return (readByte() as T);
}
case ("INT"):
{
return (readInt() as T);
}
case ("BOOL"):
{
return (readBoolean() as T);
}
case ("STRING"):
{
return (readString() as T);
}
default:
{
return default(T);
}
}
}
}
}
[/cs]