Example 1 (C #) of ASP. NET 3.5 applying LINQ and web. config

Source: Internet
Author: User
Today, I would like to show you a hello World.
Is the most simplified hello.
First, the simplest configuration of Web. config is as follows:
Explain in Code .

[Copy to clipboard]

Code:

<Configuration>
<System. Web>
<Compilation DEBUG = "false">
<Assemblies>
<Add Assembly = "system. Core, version = 3.5.0.0, culture = neutral, publickeytoken = b77a5c561934e089"/>
</Assemblies>
</Compilation>
</System. Web>
<System. codedom>
<Compilers>
<Compiler language = "C #; CS; CSHARP" extension = ". cs" WarningLevel = "4" type = "Microsoft. CSHARP. csharpcodeprovider, system,
Version = 2.0.0.0, culture = neutral, publickeytoken = b77a5c561934e089 ">
<Provideroption name = "compilerversion" value = "v3.5"/>
</Compiler>
</Compilers>
</System. codedom>
</Configuration>

The following is an explanation. System. Core. dll contains system. LINQ, so this Assembly must be added,
Of course, this Assembly may not be on the web. add the token in config, that is, the token. the Web can be removed, but you need to use the old <% @ register tagprefix = "SC" namespace = "system. LINQ "assembly =" system. core "%> and add System in Bin. core. DLL file.
The second focus is to tell him to use the v3.5 compiler. Because ASP. net3.5 actually uses ASP. after net2.0 is installed, IIS still displays 3.5. in the config file, you need to describe how to use 3.5. Otherwise, he will not recognize the VaR xxx = from cloud of LINQ.
The following is the aspx subject:

[Copy to clipboard]

Code:

<% @ Page Language = "C #" autoeventwireup = "true" %>
<% @ Import namespace = "system. LINQ" %>
<Script language = "C #" runat = "server">
Protected void page_load (Object sender, eventargs E)
{
Txtvalidated. Text = "SIPO (www.51aspx.com), and finally output :";
Int [] testnums = {787,321, 22, 1,-83 };
VaR Nums = from S in testnums where S <5 select s;
Foreach (var c in Nums) txtvalidated. Text ++ = C + ",";
}
</SCRIPT>
<Form runat = "server">
<Asp: textbox id = "txtvalidated" runat = "server" width = "800"/>
</Form>

Codebehind is not used because it saves some space. Helloworld ~ One file.
Autoeventwireup = "true" means to execute the page_load event, otherwise it will not be executed.
Here we need to import system. LINQ and use using in the CS file.
Then there is nothing to say (Author: SIPO ).

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.