문제

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