Let C # envy the VB.net property

Source: Internet
Author: User

What is XML literal?
"XML Literal" is a new feature introduced in vb.net 9.0 to build XML objects. VB.net with such artifacts, now it is the C # Programmer's envy. Of course this article does not say how to use XML literal, for more information on this new feature can be found in MSDN:
Http://msdn.microsoft.com/en-us/library/bb384629.aspx


With XML literal, how do we use it to solve the problem of multi-line strings in vb.net? See Example:

Dim SourceText as String =      <string>            Imports Microsoft.VisualBasic          Imports System          Imports System.Collections          Imports Microsoft.Win32          Imports System.Linq          Imports System.Text          Imports Roslyn.compilers          Imports System.ComponentModel          Imports System.Runtime.CompilerServices          Imports Roslyn.Compilers.VisualBasic                    Namespace HelloWorld            Module program              Sub Main (args as String ())                Console.WriteLine ("Hello, world!")              End Sub            End Module          end Namespace      </string>  

  

 

Compare the previous code, there is no heart to say "I" two words?

The obvious change is that there is no explicit type declaration of as string, which is then called later. The Value property to determine that the variable is indeed a string. In fact, compared to the above code, these two pieces of code at compile, run time and no difference. Maybe the second one is more beautiful?

What's more, we can also write:

Dim contact2 =         <contact>          <name>patrick hines</name>          <%= from P in PhoneNumbers2             Select <phone type=<%= p.type%>><%= p.number%></phone>           %>        </contact>

  

So do not laugh at the vb.net can not be convenient to write a string!!

In addition, the vb.net can not be more than a line of statements written in one line I also want to say, this before the VB6 of the product you do not know? And look at:

Dim A, b as string:a = 1:B = "ABC"

  

Let C # envy the VB.net property

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.