Search code examples
c#xamarin.androidxamarin-studio

Cast item to be type of received parametar


I have method for filtering a generic list

public bool FilterRecords(object obj)
    {
        Type ss = obj.GetType();
        var item = obj as (obj.GetType());
        .
        .
        .
        return false;
    }

Object obj can be Customer, Order, Artical, etc. Problem is that var item = obj as (obj.GetType()); does not work. I tried some more options, but I run out of ideas. How can I cast item to be type of object? Thanks in advance.


Solution

  • Sorry, I missed one option. Hence I have my class with generic parameter , I just set

    var item = (T)o;
    

    it works and there is no need for Type ss = obj.GetType();.