0

I have this situation:

public class ExtResult<T>
{
    public bool Success { get; set; }
    public string Msg { get; set; }
    public int Total { get; set; }
    public T Data { get; set; }
}

//create list object:
List<ProductPreview> gridLines;
...
...
//At the end i would like to create object
ExtResult<gridLines> result = new ExtResult<gridLines>() { 
    Success = true, Msg = "", 
    Total=0, 
    Data = gridLines 
}

But I get an error:

error: "cannot resolve gridLines"

What can I do to fix this?

1
  • "What is correct way?" - to do what? (and mostly likely the answer is to learn about generics) Commented Mar 25, 2016 at 15:00

2 Answers 2

4

gridLines is a variable, its type is List<ProductPreview> which you should use as the type parameter to ExtResult<T>:

ExtResult<List<ProductPreview>> result = new ExtResult<List<ProductPreview>>() { 
    Success = true, 
    Msg = "", 
    Total=0, 
    Data = gridLines 
};
Sign up to request clarification or add additional context in comments.

1 Comment

Of course, thank you. I was mislead by some example :)
2

You should pass a type as a generic argument, not a variable:

var result = new ExtResult<List<ProductPreview>> // not gridLines, but it's type
{ 
    Success = true,
    Msg = "",
    Total=0,
    Data = gridLines
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.