c# - Assign extension methods to a variable -


i trying assign variable extension method, getting error when hover on line.

cannot assign 'void' implicitly-typed local variable

i checking empty fields , calling extension method , wanted check more 1 field , if failing wanted them appear in 1 error box instead of them piling up.

if (drp_selectgroup.selectedvalue == "0") {   var message =  this.showmessage("select ethnic group", "error", errortype.error); } 

edit*

public static void showmessage(this page page, string message, string title, errortype err)     {         page.clientscript.registerstartupscript(page.gettype(), "toastr",             string.format("toastr.{0}('{1}','{2}');", err, message, title), addscripttags: true);     } 

the problem isn't it's extension method - it's extension method has void return type. presumably method shows message, rather creating it. you'd same error message if tried call other void method , assign result variable.

you need change extension method this:

public static string getmessage(this whatever foo, string message, string type,                                 errortype errortype) 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -