O
Ole Andre Karlson
hi
Still struggeling with Gyro...![Smile :) :)](/styles/default/custom/smilies/smile.gif)
how can this be correct?
T t = null;
gives a compile error because the compiler thinks T is a
value type.
while the test:
Type type = typeof(T);
Console.WriteLine(type.IsValueType);
gives false..
I suppose it has to do with what is known at compile time
and what is known at runtime, but why does the compiler
just asume that T is a value type if it dosn't know?
And how do I get it to understand that T is a reference
type at compile time?
code:
------------------------------
using System;
class TestClass<T>
{
public void testStuff()
{
Type type = typeof(T);
Console.WriteLine(type.IsValueType);
T t = null;
}
}
class Apple {}
class Control
{
public static void Main()
{
TestClass<Apple> t = new TestClass<Apple>();
t.testStuff();
}
}
-------------------------------
Still struggeling with Gyro...
![Smile :) :)](/styles/default/custom/smilies/smile.gif)
how can this be correct?
T t = null;
gives a compile error because the compiler thinks T is a
value type.
while the test:
Type type = typeof(T);
Console.WriteLine(type.IsValueType);
gives false..
I suppose it has to do with what is known at compile time
and what is known at runtime, but why does the compiler
just asume that T is a value type if it dosn't know?
And how do I get it to understand that T is a reference
type at compile time?
code:
------------------------------
using System;
class TestClass<T>
{
public void testStuff()
{
Type type = typeof(T);
Console.WriteLine(type.IsValueType);
T t = null;
}
}
class Apple {}
class Control
{
public static void Main()
{
TestClass<Apple> t = new TestClass<Apple>();
t.testStuff();
}
}
-------------------------------