zoukankan      html  css  js  c++  java
  • 使用密封类封装用户信息

    实现效果:

      

    知识运用:

      使用sealed关键字声明密封类

      访问修饰符 sealed clsss 类名:基类或接口{ //l类成员 }

    实现代码:

            private void button1_Click(object sender, EventArgs e)
            {
                Userinfo userinfo=new Userinfo ();
                userinfo.U="admin";
                userinfo.P="13596";
                if (textBox1.Text == userinfo.U & textBox2.Text == userinfo.P)
                    MessageBox.Show("用户名:" + textBox1.Text + "密码:" + textBox2.Text, "登陆成功",
                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                else
                    MessageBox.Show("用户或密码不正确","错误");
            }
            /// <summary>
            /// 通过sealed关键字声明密封类 防止被继承 以保护重要信息
            /// </summary>
            sealed class Userinfo {
                private string user = "";  
                private string pass="";
                /// <summary>
                /// 用户名 密码
                /// </summary>
                public string U { get { return user; } set { user =value; } }
                public string P { get { return pass; } set { pass = value; } }
            }
    

    补充说明:

    •  密封类不能作为基类被继承,但它可以继承其他类或接口
    • 在密封类中不能声明受保护的成员和虚方法
    • 因为密封类的不可继承性,因此不能声明为抽象的
  • 相关阅读:
    0004- NTFS FAT32
    0003-SQLServer 安装硬件要求
    php文件上传
    PHP 全局变量
    PHP 数组和数组排序
    PHP 函数
    PHP判断语句及循环语句
    PHP(一)
    HTTP请求组成
    扫描器的意义和利用思维
  • 原文地址:https://www.cnblogs.com/feiyucha/p/10080681.html
Copyright © 2011-2022 走看看