Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB.Net code optimization?

Tags:

vb.net

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

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 efficient is it letter A? or letter B?

Can somebody help me understand these codes?

Thanks in advance

like image 556
KG Sosa Avatar asked Jan 01 '26 06:01

KG Sosa


2 Answers

if we are talking .Net 3.5 than what 1800 INFORMATION says is not true since type inference will take place and the compiler will infer the type and hence be typesafe. so in .Net 3.5 a and B are the same.

In Visual studio 2008 just turn Option Infer On or Off to see the difference.

Before .Net 3.5 no type inference will take place and it will use the variant type or rather the object type. So in pre.Net 3.5 A and B are not the same.

like image 54
chrissie1 Avatar answered Jan 03 '26 22:01

chrissie1


In .NET 3.5 Dim x = value is the same as C# var x = value; The compiler will infer the type so both are equal at runtime.

like image 33
eWolf Avatar answered Jan 03 '26 22:01

eWolf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!