0

I have a class that contains the following method (The Class name is ZipLoad):

 private string DOit(string uName, string pWord) { DOSTUFF..... return "Successfull"; } 

Now I want pass parameters to the class using my program but there are two parameters. If there was one parameter i would simply do this:

 private string testUser; public string getSetUser { get { return testUser; } set { testUser= DOit(value); } } 

And then use my Windows Forms Application to pass the parameters.

 ZipLoad myZipLoad = new ZipLoad(); string report; myZipLoad.testUser = "userName"; report= myZipLoad.getSetUser; 

My Question is that how do I pass parameters to the DOit method using public properties in the class. One way is to make the method public but for some reason people say that is bad.

Any help would be appreciated ... Thank You

1
  • 2
    Methods are interfaces to outside world.You dont benefit much by making it private.The state(member fields) of your class should be private and not your methods. Commented Apr 30, 2013 at 6:21

1 Answer 1

1

maybe i'm wrong but set { testUser= DOit(value); } doesn't looks very useful what you are trying because if you get this to work and you are doing

myZipLoad.testUser = "userName"; report= myZipLoad.getSetUser; string user = myZipLoad.testUser; //<- user == "Successfull" 

so i build you this construct

 class Program { static void Main(string[] args) { ZipLoad myZipLoad = new ZipLoad(); string report; myZipLoad.TestUser = "userName"; report = myZipLoad.Stat; //<- modified } } class ZipLoad { #region private Values private string testUser; private string pWord; #endregion #region Properties public string TestUser { get { return testUser; } set { testUser = value; } } public string PWord { private get { return pWord; } set { pWord = value; } } // ADDED public string Stat { get { return DOit_aka_Login(testUser, pWord); } } #endregion private string DOit_aka_Login(string uName, string pWord) //<- modified { // now you may need to check the input if(uName =="" && pWord==""){...} //DOSTUFF..... return "Successfull"; } } 

if it doesn't fit your needs please add more information's

Sign up to request clarification or add additional context in comments.

7 Comments

Isn't there any way by which I don't have to make the "DOit_aka_Login()" method public ??? I mean why use properties then ??? Why don't we directly pass the parameters to the Doit_aka_Login() method ???
Yep that did it... So now I don't need to have get{} with the other two properties.. right ???
@WaqasAli right, but you also can set it as private getter private get { return ...; }
Also , what if the method does not return anything i.e void... What do I do then to get the job done ?
@WaqasAli if you test it you will see you can do myZipLoad.testUser = "userName"but you can't do string myString = myZipLoad.testUser; because the getter is private you can also set him as protected
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.