Passing values

Hi,

How can pass value from a Form to a Class in c# 2010?

Please help.

Thanks
LVL 7
ayha1999Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Umar TopiaConnect With a Mentor .Net Full Stack DeveloperCommented:
You can create a method in class which you can call with parameters like:

MyClass mc = new MyClass();
mc.CustomMethod(sFirtstName,sLastName);

or else you can create the parameterised Constructor

MyClass mc = new MyClass(sFirstName,sLastName);
0
 
himanshutConnect With a Mentor Commented:
You can use Sessions to store values that you have to pass and then pass those Session Values to method that can be used by creating instance of the Class( so that all the methods of that class can be accessed).
0
 
ayha1999Author Commented:
here I am trying access value from Form2 class into dbo2 class but ended up with error. how can I access txtRef in the dbo2 class?

the error

Error      1      The name 'txtRef' does not exist in the current context      

namespace myProject
{
   public partial class Form2: Form
   {
       public Form2 ( )
       {
          InitializeComponent ();
       }

       private void Form2_Load (object sender, EventArgs e)
       {

       }
       }

       private string txtRef=string.Empty;

       public string _Ref
       {
          set { txtRef=value; }
       }
   }

   public class dob2: DataSet
   {
       private DataTable dt2;
       string str = txtRef;   <--- values to be accepted here.

       public dob2 ( )
       {
      }
}

}

thanks
0
 
ayha1999Author Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.