标题:构造函数和方法的问题求解
取消只看楼主
qyw000
Rank: 2
等 级:论坛游民
帖 子:28
专家分:36
注 册:2010-2-5
结帖率:80%
已结贴  问题点数:8 回复次数:1 
构造函数和方法的问题求解
输入的年龄如果小于等于0或者大于100,那么年龄就默认是18
在USER类里怎么写属性
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace User_OOP
{
    class UserHelp
    {
        //用户名
        private char userID;

        public char UserID
        {
            get { return userID; }
            set { userID = value; }
        }
        //密码
        private char password;

        public char Password
        {
            get { return password; }
            set { password = value; }
        }
        //年龄
        private int age;

        public int Age
        {
            get { return age; }
            set { age = value; }
        }
        //性别
        private char sex;

        public char Sex
        {
            get { return sex; }
            set { sex = value; }
        }
    }
}
搜索更多相关主题的帖子: 问题求解 函数 构造 
2010-05-15 12:44
qyw000
Rank: 2
等 级:论坛游民
帖 子:28
专家分:36
注 册:2010-2-5
得分:0 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Data.SqlClient;

namespace User_OOP
{
    class UserHelp
    {
        //用户名
        private string userID;

        public string UserID
        {
            get { return userID; }
            set { userID = value; }
        }
        //密码
        private string password;

        public string Password
        {
            get { return password; }
            set { password = value; }
        }
        //确认密码
        private char passtoo;

        public char Passtoo
        {
            get { return passtoo; }
            set { passtoo = value; }
        }
        //年龄
        private int age;

        public int Age
        {
            get { return age; }
            set
            {
                if (age <= 0 || age >= 100)
                {
                    age = 18;
                }
                else
                {
                    age = value;
                }
            }
        }
        //性别
        private string sex;

        public string Sex
        {
            get { return sex; }
            set { sex = value; }
        }

        public UserHelp(string name, string pass)
        {
            this.UserID = name;
            this.Password = pass;

        }
        public UserHelp(string name, string pass, int age, string sex)
        {
            this.UserID = name.ToString();
            this.Password = pass.ToString();

            this.Age = Convert.ToInt32(age);
            this.Sex = sex.ToString();

        }

        public string Show(string message)
        {
            string sql = string.Format("insert into dbo.UserInfo(userID,pass,age,sex)values('{0}','{1}','{2}','{3}')", userID, password, age, sex);
            SqlCommand comm = new SqlCommand(sql, dbhelper.conn);
            dbhelper.conn.Open();
            int count = Convert.ToInt32(comm.ExecuteNonQuery());
            if (count>0)
            {
                message = string.Format(userID, password, age, sex);
                return message;
            }
            return message;
        }



    }
}
USE 类中 当我注册成功时候 MESSAGEBOX消息框弹出我注册信息
求解

在MAIN方法下怎么写,因为在类里没有MESSAGEBOX
2010-05-15 16:43



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-306757-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.104883 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved