你所在位置:首页C#.net开发 → C# 简单的例子

C# 简单的例子

发布时间:2019-06-11

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace MyLunch
{
    /// <summary>
    /// switch的用法
    /// </summary>
    ///
    public class Number
    {
         ArrayList list = new ArrayList();
        int[] intList;
        public Number()
        {

        }
        public void Input()
        {

            Console.WriteLine("这个程序是让你输入三个数,然后再按照顺序排列出来。(按X退出)");
          
            string Input;
         
            for (; ; )
            {
                Input = Console.ReadLine();
                if ("X" == Input.ToUpper())
                    break;
                else
                    list.Add(Input);


            }

        }
        public void Sort()
        {
           intList = new int[list.Count];

            Console.WriteLine(list.Count);

            //附值.

            for (int i = 0; i < list.Count; i++)
            {
                intList[i] = int.Parse(list[i].ToString());

            }
            for (int i = 0; i < intList.Length; i++)
            {
                for (int j = i + 1; j < intList.Length; j++)
                {
                    int temp;
                    if (intList[i] > intList[j])
                    {
                        temp = intList[j];
                        intList[j] = intList[i];
                        intList[i] = temp;

 


                    }

                }


            }
        }
        public void Display()
        {
            foreach (var item in intList)
            {
                Console.WriteLine(item.ToString());

            }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Number number = new Number();
            number.Input();
            number.Sort();
            number.Display();
      
          
        


        }
    }
}

 

//另外一个例子。都是蛮简单的。

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("欢迎光临本商场"+" "+"你今天花了多少钱啊");
            int input=int.Parse((Console.ReadLine()));

            string Display;
            if (input<5)
            {
                Display="你可以走了!";
               
            }
            else if(input>5&&input<20)
            {
                Display="奖励你一杯咖啡!";
            }
            else if(input>20&&input<30)
       &
上一篇:编码实现&gt;文件和输入输出&gt;Stream流
下一篇:运用C#编程通过OPC方式实现PC机与西门子PLC通讯