Click here to Skip to main content
15,901,283 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear friends,
I'm trying to create user class, where I'm trying to define properties. Take a look at code

C#
public class clsUser
{
    public clsUser()
    {
        string username;
        string pwd;
        public string username
        {
            get
            {
                return username;
            }
            set
            {
                username = value;
            }
        }
        public string pwd
        {
            get
            {
                return pwd;
            }
            set
            {
                pwd = value;
            }
        }
        public void setDetails(Hashtable hstDetails)
        {
            ArrayList  alstkeys = new ArrayList(hstDetails.Keys);
            object obj = new object();
            int intLoop;
            for(intLoop = 0; intLoop < alstkeys.Count - 1;intLoop++)
            {
                switch ((string)alstkeys[intLoop].ToString())
                {
                    
                    case "username":
                    {
                         username = (string)hstDetails["username"];
                         break;
                    }
                    case "pwd":
                    {
                         pwd = (string)hstDetails["pwd"];
                         break;
                    }
                }
            }
        }
}


While debugging following is displayed
} expected


i spend lot time no this, after that thought to post here
Any idea what is going wrong?

[edit]Code blocks tidied up - OriginalGriff[/edit]
Posted
Updated 22-Mar-11 21:50pm
v3

If you look at the indentation alone, it is fairly clear: The error message even spells it out for you:
You are missing a '}' to end your constructor:
C#
public class clsUser
{
    public clsUser()
    {
    } // <--- Add this line!
    string username;
    string pwd;
    public string username
    {
        get
I would also suggest that you change the public property names:
C#
string username;
string pwd;
public string Username
{
    get
    {
        return username;
    }
    set
    {
        username = value;
    }
}
public string Pwd
{
    get
    {
        return pwd;
    }
    set
    {
        pwd = value;
    }
}
This removes any confusion between "username" the private string and "Username" the public property.
 
Share this answer
 
Comments
Sundeep Ganiga 23-Mar-11 4:03am    
can have empty string assigned to username and pwd in constructor here....
OriginalGriff 23-Mar-11 4:47am    
Yes. Null values are perfectly legal for strings - and used quite often to indicate "unassigned".
dhage.prashant01 23-Mar-11 9:06am    
Thanks a ton. . .!!
done with it
The first thinf is that you have your field and property definitions inside the counstructor public clsUser(). So move the constructor definition after those. Another problem may be that using the same names for both fields and properties. This will cause ambiugity.
 
Share this answer
 
try this

C#
public class clsUser
        {
            string _UserName;
            string _pwd;
            public string username
            {
                get
                {
                    return _UserName;
                }
                set
                {
                    _UserName = value;
                }
            }
            public string pwd
            {
                get
                {
                    return _pwd;
                }
                set
                {
                    _pwd = value;
                }
            }

            public void setDetails(Hashtable hstDetails)
            {
                ArrayList alstkeys = new ArrayList(hstDetails.Keys);
                object obj = new object();
                int intLoop;
                for (intLoop = 0; intLoop < alstkeys.Count - 1; intLoop++)
                {
                    switch ((string)alstkeys[intLoop].ToString())
                    {
                        case "username":
                            {
                                username = (string)hstDetails["username"];
                                 break;
                            }
                        case "pwd":
                            {
                                pwd = (string)hstDetails["pwd"];
                                break;
                            }
                    }
                }
            }
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900