首页 > 学院 > 开发设计 > 正文

结构体

2019-11-11 05:10:04
字体:
来源:转载
供稿:网友
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 结构体{    class PRogram    {        static void Main(string[] args)        {            //设置控制台字体颜色  前景色            Console.ForegroundColor = ConsoleColor.Black;            Console.BackgroundColor = ConsoleColor.Yellow;            //不new 就能用是有条件的,  必须是公有的成员变量,不能是私有再封装的            Student stu;            stu.age = 20;            stu.Say();            Console.ReadKey();        }    }}
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 结构体{    //1.结构体是值类型    //2.结构体可以不new直接使用,但是是有条件的    //3.不能对结构体中的成员变量赋初值    //4.声明结构的对象后,必须对结构的成员赋初值    public struct Student    {        public int age;        public void Say()        {            Console.WriteLine("Say");            Console.ReadLine();        }    }}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表