cast as T

  • Thread starter Thread starter Dan Holmes
  • Start date Start date
D

Dan Holmes

I need to cast a value at runtime to T from object.


public class GreaterThanFilter<T> where T : IComparable
{
private T _value;
private void SetValue()
{
//DataGrid.GetValue(0, 0) returns object
_value = DataGrid.GetValue(0, 0)
// i have tried
_value = (T)DataGrid.GetValue(0, 0)
// and
_value = (T)DataGrid.GetValue(0, 0) as T
}
}

how do i get the data returned from DataGrid.GetValue into _value as T?

dan
 
Dan said:
I need to cast a value at runtime to T from object.

never mind. i changed something and it started working.
public class GreaterThanFilter<T> where T : IComparable
{
private T _value;
private void SetValue()
{
//DataGrid.GetValue(0, 0) returns object
_value = DataGrid.GetValue(0, 0)
// i have tried
_value = (T)DataGrid.GetValue(0, 0)
This is the one i ended up with.
 
Back
Top