Question

In class below, I would like to sometimes pass just an array of strings for the property 'BodyParameters'. Is that possible without using object type as its parameter type? Most times, this property will be a List of string [ ] arrays when the class is used.

public class EmailTemplate
{
    ...
    public IList<string[]> BodyParameters { get; set; }
    ...
}
Was it helpful?

Solution

If you want to set BodyParameters using only a single string[], you can do this:

string[] value = ...;
myEmailTemplate.BodyParameters = new [] { value };

There is no implicit conversion from T to IList<T>, where T is string[] in your case.

The above code will work because new [] { ... } will infer the type string[][], which implements IList<string[]>.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top