C # comparison with VB

Source: Internet
Author: User

C # is first recognized. Many terms have never been used, but after reading the materials, I gradually followed up with the idea of Chu Guangming.

As a programming language, C # has its unique characteristics and similar aspects as other languages. Here we will summarize the comparison between C # basics and VB.

I. Data Types

1. The data types of C # are divided into two types: Value Type and reference type.

Value Type, indicating the actual data. It only stores the value in the memory. The value types are all stored in the stack, including int, char, float, double, bool, structure, and enumeration.

Reference type, which indicates a pointer or reference to data. It contains the address of an object in the memory heap. If no object is referenced, It is Null, including: Class, interface, String, array, delegate, object.

2. These are lacking in VB, and C # has enumeration types, while VB does not. However, the two have one thing in common: data type conversion.

C # contains implicit conversion and display conversion, unpacking and packing. For the basic data type that represents a value, the data type with a small value range can be converted to a data type with a large value range by implicit conversion, which in turn must be converted to display. For the class type, the child type can be converted to the parent class for implicit conversion, which in turn must be converted to display, for example:

Stringstr1 = "abc ";

Object obj = str1; // The subclass is converted to the parent class, which is implicitly converted.

Stringstr2 = (string) obj; // convert the parent class to a subclass and display the conversion

In VB, we usually use a type conversion function to forcibly convert an expression to a specific data type.

For example, CBool (expression), CByte (expression), CCur (expression), and CDate (expression.

The simple data type of C # is similar to that of VB.

2. Variables and constants

Both C # and VB can declare variables and constants, but their declaration methods are different. For example:

String I // C # declare the variable method. The data type is directly followed by the variable

Dim I as string 'vb variable declaration method

In this case, C # is much less code than VB, And it looks concise.

From this example, we can see that the two annotations are different. "//" Is used in C # For annotation, and "'" is used in VB for annotation.

Iii. Syntax problems

1. C # has process control statements and Exception Handling statements like VB.

For Exception Handling statements:

In VB, on errorgoto line is often used to jump to line: when a program fails. C # provides more methods.

C # In order to handle possible situations, the related parts of the program are generally divided into three different types of code blocks:

The Code contained in the Try block is the normal operation part of the program.

The Code contained in the Catch Block handles various errors

The Finally block contains code to clear resources or execute other operations to be performed at the end of the try block. For example:

Try {// code with possible errors} Catch {// error handling} Finally {// resource cleanup}

C # there are many similarities and differences with VB. We look forward to seeing them together.

Through C # learning, I have taken another step in understanding object-oriented. I have a basic understanding of classes, objects, constructors, overloading, inheritance, abstract classes and derived classes, polymorphism and interfaces, and hope to be fully familiar with them in future use.

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.