zoukankan      html  css  js  c++  java
  • 类与方法简单使用

    students 类

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ClassLibrary1
    {
        public class Students
        {
    
            private string _name;
            public string Name
            {
                get { return _name; }
                set { _name = value; }
            }
            private int _age;
            public int Age
            {
                get { return _age; }
                set
                {
                    if (value < 0 || value > 100)
                    {
                        value = 0;
                    } _age = value;
                }
            }
            private char _gender;
            public char Gender
            {
                get {
                    if (_gender != '' && _gender != '')
                    {
                    _gender='';
                    }
                    return _gender;
                }
                set { _gender = value; }
            }
            private int _chinese;
            public int Chinese
            {
                get { return _chinese; }
                set { _chinese = value; }
            }
            private int _math;
            public int Math
            {
                get { return _math; }
                set { _math = value; }
            }
            private int _english;
            public int Englist
            {
                get { return _english; }
                set { _english = value; }
            }
            public void SayHello()
            {
                Console.WriteLine("我叫{0},我是{1}性,我今年{2}岁", this.Name, this.Gender, this.Age);
            }
            public void ShowScore()
            {
                Console.WriteLine("我叫{0},我的总成绩是{1},我的平均成绩是{2}", this.Name, this.Chinese + this.Math + this.Englist, (this.Chinese + this.Math + this.Englist) / 3);
            }
        }
    }

    program类

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ClassLibrary1
    {
        public static class Program
        {
            public static void Main(string[] args)
            {
                sz("张三", 21, '', 90, 22, 44);
                sz("李四", 28, '', 80, 52, 43);
                Console.ReadKey();
            }
            public  static void sz(string name, int age, char gender, int englist, int chinese, int math)
            {
                Students zsstudents = new Students();
                zsstudents.Name = name;
                zsstudents.Age = age;
                zsstudents.Gender = gender;
                zsstudents.Englist = englist;
                zsstudents.Chinese = chinese;
                zsstudents.Math = math;
                zsstudents.SayHello();
                zsstudents.ShowScore();
               
            }
        }
    }
  • 相关阅读:
    分享 | 自定义属于自己的U盘图标
    GIF工具 | 分享几个Gif相关工具
    XTU | 人工智能入门复习总结
    XTU | 物联网概论复习总结
    收纳箱2号 | 前端开发大全
    收纳箱1号 | GitHub Pages部署静态网页的一点私货
    博客 | 基于Travis CI实现Hexo在Github和Coding的同步自动化部署
    图床plus演示 | 图床及在线分享演示文稿工具
    css写实心正三角和倒三角
    React 多个className的写法
  • 原文地址:https://www.cnblogs.com/zywf/p/4493199.html
Copyright © 2011-2022 走看看