Co-variant Array Conversion string[] to object[] message over zealous?

Hi,

I am showing a list<string> in a ComboBox using
ComboxBox.Items.AddRange(myStringList.ToArray());

Considering that MSDN has
string[] installs = new string[]{"Typical", "Compact", "Custom"};
ComboBox1.Items.AddRange(installs);
as an example of AddRange usage would you say that this message is not warranted here?

Cheers

Adam

3 comments
Comment actions Permalink

Hello Adam
     You're right, in this case the warning is a bit overzealous because the target object[] array doesn't get written with other values. However, at the moment there's no way for ReSharper to determine that the array will not be written with other values.

Andrey Serebryansky

Senior Support Engineer

JetBrains, Inc

http://www.jetbrains.com

"Develop with pleasure!"

0
Comment actions Permalink

Is there any way to use Jetbrains Annotations to indicate that the method will not mutate the array in any way such that there is no longer a warning for the covariant calls?

 

Something like 

 

public void MyMethod([ReadOnlyArray] params IBar[] bars)

0
Comment actions Permalink

No, there is no annotation for this

0

Please sign in to leave a comment.