The Hello,world of C # Learning

Source: Internet
Author: User

1. The most basic console application

Open VS2013, new project->visual c#-> console application, name with default ConsoleApplication1, and then OK.

The code is as follows

1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Threading.Tasks;6 7 namespaceConsoleApplication18 {9     class ProgramTen     { One         Static voidMain (string[] args) A         { -Console.WriteLine ("Hello, world!."); -               //avoid a flash of the console the Console.readkey (); -         } -     } -}

It's all very simple, almost the same as Java. Then click on the upper Start button to run the results as follows:

At the same time, C # provides a number of functions for setting up the console, For example, Console.backgroundcolor can set the background color of the console, Console.foregroundcolor can set the foreground color, Console.title can set the title of the console. Modify the above code as follows

1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Threading.Tasks;6 7 namespaceConsoleApplication18 {9     class ProgramTen     { One         Static voidMain (string[] args) A         {        -               //Green background Color -Console.backgroundcolor =Consolecolor.green; the               //Font Color Red -Console.foregroundcolor =consolecolor.red; -               //Set Title -Console.title ="hello!"; +Console.WriteLine ("Hello, world!."); -               //avoid a flash of the console + Console.readkey (); A         } at     } -}

Then run the effect as follows:

There are also many programs for console settings that are not listed here.

2. Desktop applications

WPF technology is used here to create desktop applications.

New Project->visual C#->WPF application, the name takes the default WpfApplication1, OK, then a tab divided into two panes appears. The upper pane shows an empty window called MainWindow, and the lower pane shows some text, the code that generates the window. Click the common WPF component,->button, in the upper left of the screen, to add a button to the window. Double-click the button and now display the C # code in MainWindow.xaml.cs, with the following code ():

1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Threading.Tasks;6 usingSystem.Windows;7 usingSystem.Windows.Controls;8 usingSystem.Windows.Data;9 usingSystem.Windows.Documents;Ten usingSystem.Windows.Input; One usingSystem.Windows.Media; A usingSystem.Windows.Media.Imaging; - usingSystem.Windows.Navigation; - usingSystem.Windows.Shapes; the  - namespaceWpfApplication1 - { -     /// <summary> +     ///the interactive logic of MainWindow.xaml -     /// </summary> +      Public Partial classMainwindow:window A     { at          PublicMainWindow () -         { - InitializeComponent (); -         } -  -         Private voidButton_Click (Objectsender, RoutedEventArgs e) in         {    -             //here is the new code, the rest is automatically written toMessageBox.Show ("Hello, world!."); +         } -     } the}

Any string can be filled in the MessageBox.Show.

The results are as follows:

Click the button effect as follows:

The MainWindow.xaml code is as follows:

1 <Windowx:class= "Wpfapplication1.mainwindow"2 xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"3 xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"4 Title= "MainWindow"Height= " the"Width= "525">5     <Grid>6         <ButtonContent= "button"HorizontalAlignment= "Left"VerticalAlignment= "Top"Width= " the"Click= "Button_Click"/>7     </Grid>8 </Window>

This code is automatically generated and simple, and is no longer specifically explained here. Click the button to select it, and the Properties window in the lower right corner of the screen shows the properties of the button as follows

You can change the text on the button by setting the content, and now click Me instead. You can also drag the mouse button to the center of the window. The XAML code is now as follows:

1 <Windowx:class= "Wpfapplication1.mainwindow"2 xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"3 xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"4 Title= "MainWindow"Height= " the"Width= "525">5     <ButtonContent= "click Me"HorizontalAlignment= "Left"VerticalAlignment= "Top"Width= "Bayi"Click= "Button_Click"Rendertransformorigin= "2.92,6.409"Margin= "210,130,0,0"Height= " the"/>6 </Window>

The effect is as follows:

Most of the code is automatically generated and is very simple to understand, so it is not explained.

Confined to space, other basic content is not shown, and due to system reasons, it is not possible to start learning the basic Windows Phone Development tutorial, then try to fill in.

This study records this.

The Hello,world of C # Learning

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.