C# Is this initialiser really redundant?

后端 未结 6 546
故里飘歌
故里飘歌 2021-01-15 14:40

I have the following line of code:

var dmrReceived = new DownloadMessagesReport();

StyleCop and ReSharper are suggesting I remove the redun

6条回答
  •  隐瞒了意图╮
    2021-01-15 14:55

    So your code is

    var dmrReceived = new DownloadMessagesReport();
    dmrReceived = dc.DownloadNewMessages(param, param2, param3);
    

    The second line does not fill the object you created in the first line but it completely replaces that object. So the first assignment is not needed (as the first object is never used), which is what R# is warning about.

提交回复
热议问题