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

c#基础练习

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

namespace 练习
{
    class Program
    {
        static void Main(string[] args)
        {
            //第一个练习
            /*
            int sum = 0;
            int i;
            for(i=1;i<101;i++)
            {
                sum = sum + i;


            }
            Console.WriteLine("{0}",sum);

            */
            //练习2
            /*
            string s = Console.ReadLine();
            Console.WriteLine("{0}", s+"我爱你");
            int i1 = 100;
            int i2 = 300;
            Console.WriteLine(i1+"+"+i2+"="+(i1+i2));
            int s1 = 200;
            int s2 = 300;
            Console.WriteLine("{0}+{1}+{2}",s1,s2,s2+s1);
            Console.WriteLine("请输入男孩的名字");
            string boy = Console.ReadLine();
            Console.WriteLine("请输入女孩的名字");
            string girl = Console.ReadLine();
            Console.WriteLine("{0}爱{1}",boy,girl);
            //int size = "3";看起来像数字,其实是字符串
            // boy = 3;类型一旦确定就不能赋值其他类型。
            */
            //练习3
            /*
            string i = "ab";
            Console.WriteLine("{0}",i);// 打印ab,如何打印“ab”呢,看入下
            string i1="\"ab\"";
            Console.WriteLine("{0}",i1);//使用转义符\将“转义使他不被电脑认为是字符串结束,而是普通字符"a\nb"输出回车换行,想输出转义符\怎么办呢如下。
            string i2 = "a\\b";
            Console.WriteLine("{0}",i2);//双\\就可输出\,但是如果输出长路径,此方法就太麻烦,那么用什么方法解决呢,如下
            string i3=@"c\d\c\c\c\c\c\c\c";//@表示字符串中的\不当成转义符,这样就可以很方便的输出路径,注意@只针对转义符有意义
            Console.WriteLine(i3);
            Console.WriteLine("请输入第一个数字");
            string i4 = Console.ReadLine();
            int s1 = Convert.ToInt32(i4);
            Console.WriteLine("请输入第二个数字");
            int s2 = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("{0}+{1}={2}",s1,s2,s2+s1);
            int a1 = 10;
            int a2 = 20;
            Console.WriteLine("a1={0},a2={1}",a1,a2);
            int zhuan = 0;
            zhuan = a1;
            a1 = a2;
            a2 = zhuan;
            Console.WriteLine("a1={0},a2={1}",a1,a2);
            */
            //联系4
            /*
            int i = 30;
            bool q=(i==1);
            Console.WriteLine("{0},{1},{2},{3}",i,i==1,q,i=2);
            int age = Convert.ToInt32(Console.ReadLine());
            if (age > 20)
            {
                Console.WriteLine("成年人");
            }
            else
            {
                Console.WriteLine("小易做图孩");
            }
            int age1 = Convert.ToInt32(Console.ReadLine());
            if(age1>50)
            {
                Console.WriteLine("old man");
            }
            else if (age1 > 20)
           

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