Casting Object

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
 
B

Brendan Green

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>
}
 
T

Tom Spink

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();
}
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top