当前位置:编程学习 > C#/ASP.NET >>

C# 简单的例子

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

补充:软件开发 , C# ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,