Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the sugars in VB.NET grammar

2025-03-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail what are the VB.NET grammar sugars for you. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

VB.NET is a very powerful programming language. Code hosting is supported, and it runs the same way as Java. So developers who are new to the language can master some application skills in time to meet the needs of their own program development.

In VisualBasic9Beta1, there are heavyweight enhancements like LINQ, as well as some "trivial" grammatical candy. These syntax sugars do not affect the final compiled IL, but they are enough to reduce the workload of programmers and achieve more efficient and easier development.

What are the VB.NET grammar sugars?

1. Local variable type conjecture

two。 Array initializer

3. Object initializer

VB.NET grammar, how are the sweets?

Personally, I think these grammatical sweets are quite delicious. Object initializers are good; local variable type speculation is also quite easy to use.

VB.NET grammar candy how to eat?

1. Local variable type conjecture

Prior to VisualBasic9, you could only define a strongly typed object with an as statement. In VB9, the type declaration of local variables is allowed to be exempted, as determined by the initialization statement. Look at the example:

Before 'Visual Basic 9, Dim List As List (Of String) = New List (Of String)' Visual Basic 9 Dim List = New List (Of String)

Don't worry about performance issues; it is speculated by the compiler at compile time and is a strongly typed feature.

At the same time, VB9 also supports the loop variable conjecture of For (ForEach), so there is no need to define loop variables temporarily.

Dim Sample As Integer (5) 'Visual Basic 9 before For Each I As Integer In Sample Next' Visual Basic 9 For Each I In Sample Next

two。 Array initializer

VisualBasic9 introduces a simplified array definition method (though not as simple as Ninputer says), which can help programmers reduce the code workload. It's simple. Look at the code:

Before 'Visual Basic 9, Dim OldArr As Integer () = New Integer () {1,2,3}' Visual Basic 9 Dim NewArr As Integer () = {1,2,3}

3. Object initializer

Object initializer is an important syntax enhancement, which is of great help to Coding. We know that in VisualBasic8 and previous versions, you had to create a class by assigning attributes one by one. In VisualBasic9, everything is different:

'Visual Basic 8 Dim OldArea As NewArea With OldArea .subject = "Beijing" End With' Visual Basic 9 Dim NewArea As NewArea With {. Subject = "Beijing"}

This grammatical expression extends what an "expression" can express, like putting a With statement into an initialization statement. Since then, many functions that would have required several lines of code can be integrated into one sentence.

This is the end of this article on "what are the VB.NET grammar sugars?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report