深入.NET 第二章 练习

C#结构体与数组应用
本文通过实例演示了C#中结构体的使用方法及其特性,并介绍了如何进行数组操作来实现具体的功能需求。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 深入.NET_第二章
{
   
        //1.结构体是值类型
        //2.结构体可以不new直接使用,但是是有条件的
        //3.不能对结构体中的成员变量赋初值
        //4.声明结构的对象后,必须对结构的成员赋初值
        
    //public struct Student
        //{
        //    public int age;
        //    public void Say()
        //    {
        //        Console.WriteLine("Say");

     public class Student
    {
    ////上机1  
    
    //    int[] points = new int[5];
    //    int[] newpoints = new int[5];

    //    public void yi(){

    //        Console.WriteLine("请输入五位会员的积分:");
    //        for (int i = 0; i <points.Length ; i++)
    //        {
    //            Console.WriteLine("请输入第"+(i+1)+"位会员的积分:");
    //            points[i] = Convert.ToInt32(Console.ReadLine());
    //        }

    //        //数组复制
    //        for (int j = 0; j < points.Length; j++)
    //        {
    //            newpoints[j] = points[j];
    //            newpoints[j] = points[j] + 500;//赠送500积分
    //        }

    //        Console.WriteLine("\n序号\t\t历史积分\t\t新年积分");
    //        for (int k = 0; k < points.Length; k++)
    //        {
    //            Console.WriteLine("\n"+(k+1)+"\t\t"+points[k]+"\t\t\t"+newpoints[k]);
    //        }
    //        Console.WriteLine("按任意键继续!!!!!");

         // 上机2 
        string[] qian = new string[3];
        string[] hou = new string[3];
         -
        public void e()
        {

            qian[0] = "hpCQ-217TX";
            qian[1] = "Mc24OCH/A";
            qian[2] = "SYNW18H/W";
            Console.WriteLine("***************设置计算机ID前***************");
            Console.WriteLine("计算机型号\t计算机ID\t购买时间");
            for (int i = 0; i < qian.Length; i++)
            {
                Console.WriteLine(qian[i] + "\t" + "" + "\t\t" + "2013-10-5");
            }
            Random r = new Random();
            Console.WriteLine("\n***************设置计算机ID后***************");
            Console.WriteLine("计算机型号\t计算机ID\t购买时间");
            for (int i = 0; i < qian.Length; i++)
            {

                string suiji = r.Next(1000, 10000).ToString();
                hou[i] = qian[i] + "-" + suiji;
                Console.WriteLine(qian[i] + "\t" + hou[i] + "\t" + "2013-10-5");
            }
        }
            
        }
    }

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

namespace 深入.NET_第二章
{
    class Program
    {
        static void Main(string[] args)
        {  //////     值类型  
          //  int heightzhang = 178;
          //  int heightlihuohuo = heightzhang;
          //  Console.WriteLine("去年张浩的身高是:" + heightzhang + ",火火的身高是:" + heightlihuohuo);
          //  Console.WriteLine("-------------我是分割线------------------");
          //  heightlihuohuo = 280;
         
          //Console.WriteLine("今年张浩的身高是:" + heightzhang + ",火火的身高是:" + heightlihuohuo);
          //Console.ReadLine();   
   

           // 引用类型   --- 
            //int[] infozhang = new int[]{170,50};//张浩身高体重 
            //int[] infolihuohuo = infozhang;

            //Console.WriteLine("去年张浩的身高是:" + infozhang [0]+ "体重是:"+infozhang[1]+",火火的身高是:" + infolihuohuo[0]+"体重是:"+infolihuohuo[1]);
        

            //infolihuohuo[0] = 180;
            //infolihuohuo[1] = 60;
            //Console.WriteLine("今年张浩的身高是:" + infozhang[0] + "体重是:" + infozhang[1] + ",火火的身高是:" + infolihuohuo[0] + "体重是:" + infolihuohuo[1]);
            //Console.ReadLine();

            // 引用类型   ---   for循环终极版
            //int[] infozhang = new int[] { 170, 50 };//张浩身高体重 
            //int[] infolihuohuo = new int[2];

            //Console.WriteLine("复制前 -- 火火身高是:" + infolihuohuo[0] + "体重是:" + infolihuohuo[1]);

            //// 数组复制 
            //for (int i = 0; i < infozhang.Length; i++)
            //{
            //    infolihuohuo[i] = infozhang[i];
            //}
            //Console.WriteLine("去年张浩的身高是:" + infozhang[0] + "体重是:" + infozhang[1] + ",火火的身高是:" + infolihuohuo[0] + "体重是:" + infolihuohuo[1]);


            //infolihuohuo[0] = 180;
            //infolihuohuo[1] = 60;
            //Console.WriteLine("今年张浩的身高是:" + infozhang[0] + "体重是:" + infozhang[1] + ",火火的身高是:" + infolihuohuo[0] + "体重是:" + infolihuohuo[1]);
            //Console.ReadLine();


            // 结构  
           //设置控制台字体颜色  前景色
            //Console.ForegroundColor = ConsoleColor.Red;
            //Console.BackgroundColor = ConsoleColor.Yellow;



            ////不new 就能用是有条件的,  必须是公有的成员变量,不能是私有再封装的
            //Student stu;
            //stu.age = 20;
            //stu.Say();
            //Console.ReadKey();




            //上机一
            //Student a = new Student();
            //a.yi()

            //上机二
            Student b = new Student();
            b.e();
            Console.ReadLine();


        }


        }

    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值