• C# 练习


    第一单元

    1.

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using System.Threading.Tasks;

    namespace _17._9._18
    {

     class Program
        {
            static void Main(string[] args)
            {
                Console.Write("请输入一个整数:");
                int n = int.Parse(Console.ReadLine());
                int sum=0;
                if(n%2!=0)
                {
                    for(int i=1;i<=n;i++)
                    {
                        if (i % 2 != 0)
                            sum += i;
                    }
                    Console.Write("该数及比该数小的所有奇数之和为:");
                    Console.WriteLine(sum);
                    Console.Read();
                }
                else
                {
                    for (int j = 2; j <= n; j++)
                    {
                        if (j % 2 == 0)
                            sum += j;
                    }
                    Console.Write("该数及比该数小的所有偶数之和为;");
                    Console.WriteLine(sum);
                    Console.Read();
                   
                }
            }
        }
    }

    11.

    第二单元

    1.

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    namespace Animal
    {
        class animal
        {
            public virtual void DU()
            {
            }
        }
        class dog : animal
        {
            public override void DU()
            {
               
                Console.WriteLine("This is a dog!!");
               
            }
        }
        class cat : animal
        {
            public override void DU()
            {    
                Console.WriteLine("This is a cat!!");
            }
        }
        class an : animal
        {
            public override void DU()
            {     
                Console.WriteLine("This is animal!! ");
            }
        }
    }

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

    namespace Animal

    {   

      class Program

        {      

       static void Main(string[] args)    

         {             

                dog s = new dog();       

                  s.DU();              

           cat j = new cat();          

               j.DU();                   

      an y = new an();             

            y.DU();

                Console.Read();     

        }   

      }

    }

    11.

       

  • 相关阅读:
    APS.NET MVC + EF (14)---项目框架搭建
    APS.NET MVC + EF (11)---过滤器
    APS.NET MVC + EF (10)---使用AJAX
    APS.NET MVC + EF (06)---模型
    APS.NET MVC + EF (08)---数据注解和验证
    APS.NET MVC + EF (07)---表单和HTML辅助方法
    APS.NET MVC + EF (05)---控制器
    错误 1 error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
    VS2010中项目配置引入GDAL
    Win7(32/64)VS2010配置编译GDAL环境(图文教程+亲测可用!)
  • 原文地址:https://www.cnblogs.com/wxw835036135/p/7536673.html
Copyright © 2020-2023  润新知