C# 简单的例子

来源:互联网 发布:手机连接电脑 软件 编辑:程序博客网 时间:2024/05/05 22:20

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)
       &

原创粉丝点击