Casting Object

  • Thread starter Thread starter thomson
  • Start date Start date
T

thomson

Hi All,
i do have a function where in which it instantiates an
object


eg: private void myfun()
{
Customer objCustomer =new Customer();
// I want to pass this objCustomer to another function i tried this
callanother(objCustomer)

}

private void callanother(Object objCus)
{
objCus.//Error
}


Iam getting an error in this point would any please let me know how do
i send object to different functions


Thanks in Advance

thomson
 
Change

private void callanother(Object objCus)
{
objCus.//Error
}

To

private void callanother(Customer objCus)
{
objCus.<whatever>
}

or (not so good)

private void callanother(Object objCus)
{
Customer c = (Customer)objCus; // error handling and validation should
be done!
c.<whatever>
}
 
thomson said:
Hi All,
i do have a function where in which it instantiates an
object


eg: private void myfun()
{
Customer objCustomer =new Customer();
// I want to pass this objCustomer to another function i tried this
callanother(objCustomer)

}

private void callanother(Object objCus)
{
objCus.//Error
}


Iam getting an error in this point would any please let me know how do
i send object to different functions


Thanks in Advance

thomson

Hi Thomson,

It would be helpful to know the error you're getting. Could you post the
error message, please?

Also, have you tried something like this:

///
private void callanother ( object objCus )
{
Customer c = objCus as Customer;

if ( c == null )
return;

c.DoSomething();
}
///
 
Back
Top