Error: Cannot implicitly convert type 'void' to 'System.Collections.Generic.List'

后端 未结 7 1163
后悔当初
后悔当初 2021-01-07 21:59

I am trying to set a property of my .ascx controls from an .aspx using that control.

So in one of my .aspx which has this control in it, I have the

相关标签:
7条回答
  • 2021-01-07 22:42

    For others who might come here from Googling the error:

    Sometimes it's because you didn't finish writing a line but it compiles anyway and the error only shows up on the next line which can be confusing/misleading if you don't pay attention. Eg:

    var foo = 33;
    var bar = 
    
    // Note that I never finished the assignation (got distracted, saved and it compiled)
    //
    // Some unrelated code returning "void" (another example would be List.Add)
    await SomethingAsync(); // -> Error shows up here instead
    

    Might save some of you all some headache trying to figure why "awaiting on my function" raises a "Cannot convert void to X", when really it's not the actual issue.

    0 讨论(0)
提交回复
热议问题