C#学习笔记01

来源:互联网 发布:windows窗口概念 编辑:程序博客网 时间:2024/06/10 03:17

    早在9月底的时候就准备开始学C#,看了些楚广明的视频教程,觉得还不错吧,国庆到广州玩了几天回学校就要开始准备10月底也就是前几天的考试,也就暂时把C#这个学习任务给放下了,今天开始速攻!

    我是个初学者,所以有些错误很正常,欢迎大家指正,希望能帮到同样跟我一起刚开始学习C#的人。以下进入正题:

 

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace ConsoleApplication1
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             Console.WriteLine("something show here~");
  11.         }
  12.     }
  13. }

    这段代码发挥出他功能的代码只要看    Console.WriteLine("something show here~");,正如英文字面意思,console.WriteLine();代码是用来输出功能的。类似于ASP中的response,JSP,JAVA,C等的print功能一样,很容易理解。

    第二个建的是windows窗口的程序,只是让大家看看VS编写这类程序比JAVA编写的异同之处,方便很多的说。

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. namespace WindowsApplication1
  9. {
  10.     public partial class Form1 : Form
  11.     {
  12.         public Form1()
  13.         {
  14.             InitializeComponent();
  15.         }
  16.         private void button1_Click(object sender, EventArgs e)
  17.         {
  18.             MessageBox.Show("您的计算机正处于危险中!!");
  19.         }
  20.     }
  21. }

    首先请大家无视"您的计算机正处于危险中!!这几个字....调试后会出现刚才制作的一个窗口,点击窗口中的按钮时会弹出窗口并显示上面的中文,比JAVA来说方便不少。

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace Chapter01
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int myInteger;
  11.             string myString;
  12.             myInteger = 17;
  13.             myString = "/"myInteger/"is";
  14.             Console.WriteLine("{0}{1}", myString, myInteger);
  15.         }
  16.     }
  17. }

    这里要注意下myString = "/"myInteger/"is";中的/" 是用来表示“" ”的,因为如果直接用"会出现编译错误,后面的Console.WriteLine("{0}{1}", myString, myInteger);就相当于C中的print(%d,a);这种赋值吧。

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace Yunsuan
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             double firstNum, secondNum;
  11.             string userName;
  12.             Console.WriteLine("Enter your name please");
  13.             userName = Console.ReadLine();
  14.             Console.WriteLine("Welcome {0}",userName);
  15.             Console.WriteLine("Now enter a number:");
  16.             firstNum = Convert.ToDouble(Console.ReadLine());
  17.             Console.WriteLine("Now give another number:");
  18.             secondNum = Convert.ToDouble(Console.ReadLine());
  19.             Console.WriteLine("the sum of {0} and {1} is {2}",firstNum,secondNum,firstNum+secondNum);//加法
  20.             Console.WriteLine("the result of subtracting {0} and {1} is {2}",firstNum,secondNum,firstNum-secondNum);//减法
  21.             Console.WriteLine("the product of {0} and {1} is {2}",firstNum,secondNum,firstNum*secondNum);//乘法
  22.             Console.WriteLine("the dividing of {0} and {1} is {2}", firstNum, secondNum, firstNum / secondNum);
  23.             Console.WriteLine("the remainder of {0} and {1} is {2}",firstNum,secondNum,firstNum%secondNum);
  24.         }
  25.     }
  26. }

 

    最后一段代码看似复杂很多,但认真看的话还是比较简单的,拆开来就只有三步:

1.输入你的姓名

2.任意输入一个数

3.任意再输入一个数

4.分别计算加,减,乘,除,取余运算

    今天就学了些最最基本的,现在继续看书,今天或者明天继续更新本文或开新贴更新。

原创粉丝点击