Use JScript. NET to create an asp.net page (2)

Source: Internet
Author: User
Tags glob numeric
To enable the Jscript.net function to deduce the variable type, you need to follow the following rules!
1. Declare your local variables forever. This seems obvious, but it is very important. Jscript.net can only infer your local variables, not global variables. If you do not declare it and use it directly, it becomes a global variable and cannot be optimized.
2. Only one data type is used. If you declare a numeric variable but store the numeric data, Jscript defines the variable as generic Object or variant.
// The data type cannot be inferred -- glob is a global variable.
Var glob = 42;
Function myfunc ()
{
// The type cannot be inferred -- s is not defined, so it is treated as a global variable.
S = "hello ";
// Inferred type
Var I = 0;
// The data type cannot be inferred.-q is assigned to another type.
Var q = new Date ();
Q = 3.14159;
}
Although type inference is a good function, it still has some disadvantages. It cannot help us capture type mismatch or other errors. To solve this problem, Jscript.net provides a way to clearly define the type of a variable. Through examples, you can easily understand how to use it.
// Define the value type
Var myInt: int = 42;
// Define a function and return a string
Function GetName (): String
{
// Program line
}
// Define a function with two parameters to return a logical type
Function CheckNumber (dVal: double): Boolean
{
// Function code <

Related Article

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.