C# 《一》基本知识 (2)

第一个控制台程序

 

1、控制台程序  (Console Application)

2、为兼容 MS -DOS 而创建的一种程序,此程序只有一个单一的界面。

 

3、打开控制台的方法:

                             1) Ctrl + r

                             2)cmd

                             3)enter

4、新建项目的一个方法:

     1)先学习两句话:  

Console.WriteLine("Hello World!") ;   //这句话是用来输出文字到屏幕上
Console.ReadKey();    //等待用户输入,常用来对程序界面进行停留 

 OK ,代码写完了,怎么样运行这个有两行代码编写的程序呢!(技巧)

Console.WrlteLine();

输入:CW   按下 Tab 两次

5、C#中的三种注释符

       1)第一个:单行注释    以  //  开头,后面的就是注释内容    //  单行注释

       2)第二种:多行注释   以  /*  开头            */结束   之间的是注释内容     /*  */   多行注释

       3)第三种:文档注释   在方法或类的上一行输入   ///  就会产生           ///      ///   文档注释    ///

       4)代码执行时会自动忽略注释

如下程序:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _1._5第一个控制台程序
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Holle World!");   //这句话是用来输出文字到屏幕上
            Console.WriteLine("欢迎来到自学网学习由雪上行者讲解的C#入门编程!");
            Console.ReadKey();       //等待用户输入,常用来对程序界面进行停留
           // jiejieawwoj    单行注释

           /*
           154664
            4643641 
                5846   */
                        // 多行注释
        }
    }
}

运行结果:

 

 

第一个桌面程序

 

1、先学习一句话 :

MessageBos.Show("Hello World!");

用于弹出一个消息框

2、本节的示例介绍建立桌面应用程序用户界面的基本知识,说明如何启动和运行 Windows 应用程序。

步骤:

        1)创建WPF Application 的新项目;也可使用 WindowsForms 来创建桌面应用程序。

        2)布局按钮;

        3)添加代码:

MessageBox.Show("Hello World ! 这是我自学创建的第一个桌面应用程序");

如下程序:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace _1._6第一个桌面应用程序
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();  //初始化主窗口
            
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("这是我要自学网的学习的第一个桌面应用程序 ! !","我自定义的消息框的标题");
        }
    }
}

运行结果:

 

本章知识总结及任务实施

 

     1、区分.net 与 C#;

     2、常用集成开发环境简介(IDE);

     3、Visual Studio (VS) 程序初始化及各个组成部分;

     4、.net Framework 编写应用程序的过程;

     5、第一个控制台程序;

     6、第一个桌面应用程序。

 

技巧: 新建 (Ctrl + Shift + N)

           运行(F5 或 Ctrl + F5)

           输入:

Console.WritLine("  ");

       (CW  按下Tab两次)

编写代码中需要注意的问题

 

1、写代码切忌括号错误!!!

2、代码中所有的标点都是英文半角的标点。

3、C#代码中每行代码以分号结束。

 

习题1:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _01_练习
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("****************************************");
            Console.WriteLine("*     我要自学网学习的第一个程序       *");
            Console.WriteLine("****************************************");
            Console.ReadKey();
        }
    }
}

运行结果:

 

posted @ 2017-08-19 13:38  让优秀成为一种习惯  阅读(350)  评论(0编辑  收藏  举报