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.
                    
                
                
            
        
浙公网安备 33010602011771号