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; }
    ...
}
有帮助吗?

解决方案

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[]>.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top