Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
1st make This Class
C#
{
    public class Customer
    {
        public Customer()
        {

        }
        private string m_Name;

        public string Name
        {
            get { return m_Name; }
            set { m_Name = value; }
        }

        private string m_CusCode;

        public string CusDese
        {
            get { return m_CusCode; }
            set { m_CusCode = value; }
        }


    }
}


And 2nd Step this Class
C#
public Customer GetCustomer(string pCusCode)
       {
           Customer c = new Customer();
           c.Name = "asif";
           return c;
       }



And 3rd MAke This Class

private void button1_Click(object sender, EventArgs e)
        {
            Customer c2 =  new Customer();
            GetCustomer("18-020-00000005");
            textBox1.Text = c2.Name;
        }

       

        private void Form1_Load(object sender, EventArgs e)
        {

        }


at 2nd Step Data Show name etc all and return c properly <<
but when "button" function load there is no data in any variable
what mistake i have done???
Posted

Hello,

Change button1_click as shown below.
C#
private void button1_Click(object sender, EventArgs e)
{
    Customer c2 =  Customer.GetCustomer("18-020-00000005");
    textBox1.Text = c2.Name;
}

Forgot to add following
Make the GetCustomer mthod as static
C#
public static Customer GetCustomer(string pCusCode)
{
    Customer c = new Customer();
    c.Name = "asif";
    return c;
}

Regards,
 
Share this answer
 
v2
Comments
saimm 29-Apr-13 3:05am    
if not make object so how can call GetCustomer Function???
Prasad Khandekar 29-Apr-13 8:33am    
Hello,
Thank's for pointing out it ASAP. Actually forgot to add other part. Updated the solution.
saimm 29-Apr-13 23:01pm    
welcome yeah now is working thanks alot...
Hi saimm,

I hope assigning returning object to another object would resolve the issue.
Try the below code.

Customer c2 = new Customer();
c2= GetCustomer("18-020-00000005");

But why in the earth you are passing that string value to GetCustomer() function ;-)

Regards,
RK
 
Share this answer
 
v2
Comments
saimm 29-Apr-13 23:01pm    
thanks its working
Hi saimm,

1. Error: You don't assign the result of GetCustomer to your c2 variable. Btw. you don't need to assign it twice. So do it like this:

Customer c2 = GetCustomer("blablabla");
textbox1.Text = c2.Name;


2. Error: You do nothing with the string parameter pCusCode in the GetCustomer method. So there is no effect in calling GetCustomer with different parameters....
 
Share this answer
 
Comments
saimm 29-Apr-13 23:00pm    
thanks its working
C#
private void button1_Click(object sender, EventArgs e)
        {
            Customer c2 =  GetCustomer("18-020-00000005");
            textBox1.Text = c2.Name;
        }



try this your method return object of class so use the above code.
 
Share this answer
 
Comments
saimm 29-Apr-13 23:00pm    
thnks

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