New Understanding of C #

Source: Internet
Author: User

In the past, I learned that C # Only knows that it contains console programs and Windows Application Forms programs. I generally know that Windows Application Forms programs can be generated. . Today, we found that there are no fewer applications on the console than Windows application forms. I just didn't know it before. I was shocked by the fact that I knew the console program could be used as an interface application. I thought it was a little fun and dispelled my previous understanding. Although the program encountered great technical difficulties, but technical problems can be solved, cultivating interest in C # is the most important. If you are interested, you will have the motivation to learn. The technical aspects can be gradually accumulated. Just like a small program for this calculator, you can use the console to implement interface applications, large programs, such as bank programs, are also made on the console. At present, I still have little understanding of C #. I will learn how to accumulate it in the future. New features added in C #3.0

VaR and anonymous types:

(1) var:

Variables declared in the method range can have implicit type var. Implicit local variables force type variables, but are determined by the compiler.

VaR I = 10; it is automatically interpreted as int I = 10 during underlying compilation; similar to the VaR type in JavaScript.

(2) Anonymous type:

The anonymous type is used to encapsulate a set of read-only attributes into a single object without explicitly defining a type. The type name is generated by the compiler and cannot be

Source code-level usage. The property type is inferred by the compiler.

VaR v = new {amount = 108, message = "hello "};

V. Amount and V. message can be called directly.

The following is a simple program for playing the piano on the C # console:

Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;

Namespace shengyin
{
Class Program
{
Static void main (string [] ARGs)
{

Console. backgroundcolor = consolecolor. Gray;
While (true)
{
Consolekeyinfo cki = console. readkey (true );
Int num = cki. keychar-48;
Write (Num );
// Console. writeline (cki. keychar );

}
}
Static void write (INT Yb)
{

Switch (Yb)
{

Case 1:

Console. Beep (14*37,200 );
// Console. writeline (cki. keychar );
Break;
Case 2:

Console. Beep (16*37,200 );
Console. backgroundcolor = consolecolor. darkred;
// Console. writeline (cki. keychar );
Break;
Case 3:

Console. Beep (18*37,200 );
Console. backgroundcolor = consolecolor. White;
// Console. writeline (cki. keychar );
Break;
Case 4:

Console. Beep (19*37,200 );
Console. backgroundcolor = consolecolor. Yellow;
// Console. writeline (cki. keychar );
Break;
Case 5:

Console. Beep (21*37,200 );
Console. backgroundcolor = consolecolor. darkcyan;
// Console. writeline (cki. keychar );
Break;
Case 6:

Console. Beep (23*37,200 );
Console. backgroundcolor = consolecolor. darkgreen;
// Console. writeline (cki. keychar );
Break;
Case 7:

Console. Beep (25*37,200 );
Console. backgroundcolor = consolecolor. darkmagenta;
// Console. writeline (cki. keychar );
Break;
Case 8:

Console. Beep (28*37,200 );
Console. backgroundcolor = consolecolor. blue;
// Console. writeline (cki. keychar );
Break;
Default:
Break;
}
For (INT I = 0; I <Yb; I ++)
{
Console. Write ("");
}
/// Console. writeline (Yb );

}

}




}

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.