PC Review


Reply
Thread Tools Rate Thread

Casting Object

 
 
thomson
Guest
Posts: n/a
 
      26th Jun 2006
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

 
Reply With Quote
 
 
 
 
Brendan Green
Guest
Posts: n/a
 
      26th Jun 2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
Tom Spink
Guest
Posts: n/a
 
      26th Jun 2006
thomson wrote:

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

--
Hope this helps,
Tom Spink
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Casting and iteration in object of type object eliassal Microsoft Dot NET 2 8th Jan 2010 05:59 PM
casting from object Tony Johansson Microsoft C# .NET 0 23rd Sep 2008 10:11 PM
issue type casting derived object to base object Microsoft C# .NET 2 7th Sep 2007 07:26 AM
Object casting =?Utf-8?B?bWdvbnphbGVzMw==?= Microsoft C# .NET 2 23rd May 2006 02:48 PM
casting from object Karl Meissner Microsoft C# .NET 2 28th Jul 2003 05:47 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:36 AM.