ASP.NET C#: Will <%:myInt%> result in boxing? -


passing value type type object function in c# , boxing occurs.

in asp.net have shorthand's response.write(..) , response.write(server.htmlencode(..)) respectively, <%= , <%:

response.write(..) exist overloads char, string , object - therefor assume code result in response.write(object) being called , int being boxed:

<%int myint = 3;%> <%=myint%> 

while understand version not result in boxing:

<%=myint.tostring()%> 

(correct me if i'm wrong here)

but <%:?

server.htmlencode() takes string parameter , can not called type of object. happening in situation:

<%:nyint%> 

will webform view engine "compile"

response.write(server.htmlencode(myint.tostring)) 

a "magic no boxing" scenario?

update

following joe’s example shows <%:nyint%> translated to

@__w.write(system.web.httputility.htmlencode(myint));

system.web.httputility.htmlencode has overload object - means conclusion <%: myint%> cause boxing - regardless of whether cause performance penalty or not :-)

if want know generated source code looks like, easy way add script page deliberate compile-time error, e.g.

    <script runat="server">          deliberate error here     </script> 

the error page displayed when compile fails includes link view complete generated source code, answer questions above.

as boxing, shouldn't concerned.

repeatedly boxing , unboxing can have performance penalty, e.g.:

object myint; ... (i=0; i<averylargenumber; i++) {     ...     myint = ((int)myint)+1;     ... } 

but in example above, there no reason concerned.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -