VB.Net code optimization?

I would like to humbly ask those vb.net experts regarding code optimization. My example is here

a.

Dim lblEventCategory = CType(Me.gvSpecialEvent.Rows(e.NewEditIndex).FindControl("lblEventCategory"), Label)

b.

 Dim lblEventCategory As Label = CType(Me.gvSpecialEvent.Rows(e.NewEditIndex).FindControl("lblEventCategory"), Label)

Which of the two is more effective is this letter A? or letter B?

Can someone help me understand these codes?

Thank you in advance

+3
source share
3 answers

if we say .Net 3.5, which 1800 says, this is not so, since type inference will take place, and the compiler will infer the type and therefore will be typeafe. therefore .Net 3.5 a and B are the same.

In Visual Studio 2008, just enable the Infer On or Off option to see the difference.

Prior to .Net 3.5, there would be no type inference, and it would use the variant type or, rather, the object type. So, in pre.Net 3.5, A and B do not match.

+4
source

.NET 3.5 Dim x = # var x = value; , .

+2

lblEventCategory Variant. , , . Variant - "catch all", , , . Variant - , .

, "" - , , , . , , "" (.. ).

On the other hand, types of options have their place. They are useful in OLE Automation Programming (COM) if you interact with a language such as VBScript that only supports variant types. In this situation, it might be wise for you to wrap calls in late code so that the Variant type is converted to and from the desired type on the border of the call.

0
source

Source: https://habr.com/ru/post/1709504/


All Articles