With..End With statement

Visual Basic provides an alternative way for invoking object members that is the With..End With statement. Consider the following code block, in which a new Person class is instantiated and then properties are assigned while methods are invoked:

image

Using a With..End With statement you just need to specify the name of the class once and then simply type a dot so that IntelliSense shows up members that you can use, as follows:

image

There is no difference between the two coding techniques, so feel free to use the one you like most. With..End With just offers the advantage of speeding the code writing up a little and can be useful if you have a lot of members to invoke or assign at one time.

With..End With Note

With..End With has no equivalent in other .NET languages, so if you have to interoperate it could be a good idea assigning members the normal way. Although the compiler translates the With..End With blocks as single members’ invocations, in such scenarios the best approach is a .NET-oriented coding style more than a VB-oriented one.

Summary

Every development environment relies on data types. Basically the .NET Framework relies on two kinds of data types: value types and reference types. Both kinds of types are managed by the Common Type System, which provides a common infrastructure to .NET languages for working with types. In this chapter you learned the important basics of the .NET development and the Visual Basic language, which can be summarized as follows:

• Common Type System

• Value types and reference types

System.Object and inheritance levels in value types and reference types

• Memory allocation of both value types and reference types

• Converting between types and conversion operators

• Most common value types and reference types

• Common operators

You often need to work with and analyze data types. Visual Basic 2010 provides several ways for performing work on types and data they store. To accomplish this you can use

• Iterations, such as For..Next and For..Each

• Loops, such as Do..Loop

• Conditional code blocks, such as If..End If and Select Case..End Select

It’s important to understand all the preceding features because they often recur in your developer life; these features appear extensively in the rest of the book. But you also might encounter errors when working with types. The next two chapters discuss two fundamental topics in the .NET development with Visual Basic: debugging and handling errors.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.111.134