Click here to Skip to main content
16,009,057 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
public class mUIPassword
{
public mUserPasswords user { get; set; }
public string channel { get; set; }
public string lang { get; set; }
mUIPassword()
{
channel = "device|Web";
lang = "en";
}
}
public class mUserPasswords
{
public string newPassword { get; set; }
public string oldPassword { get; set; }
}

What I have tried:

Here how can I assign user property?
Posted
Updated 30-May-18 3:02am

1 solution

Private constructors are used when the class needs to maintain control over the instances that are created (most often as a Singleton class where there is only ever one instance of the class created).
In those circumstances, the class needs to provide a method to create and return an instance, or the non-static properties and methods cannot be accessed at all (since they require an instance in order to be used).

So in your specific example, the answer is "you can't".
But you can if you provide a method as mentioned:

public class mUIPassword
    {
    public mUserPasswords user { get; set; }
    public string channel { get; set; }
    public string lang { get; set; }
    private mUIPassword()
        {
        channel = "device|Web";
        lang = "en";
        }
    private static mUIPassword theInstance = null;
    public static mUIPassword GetInstance()
        {
        if (theInstance == null) theInstance = new mUIPassword();
        return theInstance;
        }
    }
 
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