Skip to main content
slightly changed the formatting, highlighting the syntax
Source Link
  1. That is correct. When you do that you are casting it it into an "employee"employee object, so that means you cannot access anything manager specific.

  2. Downcasting is where you take a base class and then try and turn it into a more specific class. This can be accomplished with using is and an explicit cast like this:

     if (employee is Manager)
     {
         Manager m = (Manager)employee;
         //do something with it
     }
    

or with the asas operator like this:

Manager m = (employee as Manager);
if (m != null)
{
    //do something with it
}

If anything is unclear I'll be happy to correct it!

  1. That is correct. When you do that you are casting it it into an "employee" object, so that means you cannot access anything manager specific.

  2. Downcasting is where you take a base class and then try and turn it into a more specific class. This can be accomplished with using is and an explicit cast like this:

     if (employee is Manager)
     {
         Manager m = (Manager)employee;
         //do something with it
     }
    

or with the as operator like this:

Manager m = (employee as Manager);
if (m != null)
{
    //do something with it
}

If anything is unclear I'll be happy to correct it!

  1. That is correct. When you do that you are casting it it into an employee object, so that means you cannot access anything manager specific.

  2. Downcasting is where you take a base class and then try and turn it into a more specific class. This can be accomplished with using is and an explicit cast like this:

     if (employee is Manager)
     {
         Manager m = (Manager)employee;
         //do something with it
     }
    

or with the as operator like this:

Manager m = (employee as Manager);
if (m != null)
{
    //do something with it
}

If anything is unclear I'll be happy to correct it!

Fixed up a mis-named variable
Source Link
ib.
  • 28.6k
  • 12
  • 84
  • 103

1: That is correct. When you do that you are casting it it into an "employee" object, so that means you cannot access anything manager specific.

2:

Downcasting is where you take a base class and then try and turn it into a more specific class. This can be accomplished with using is and an explicit cast like this:

if (employee is Manager)
{
    Manager m = (Manager)employee;
    //do something with it

}
  1. That is correct. When you do that you are casting it it into an "employee" object, so that means you cannot access anything manager specific.

  2. Downcasting is where you take a base class and then try and turn it into a more specific class. This can be accomplished with using is and an explicit cast like this:

     if (employee is Manager)
     {
         Manager m = (Manager)employee;
         //do something with it
     }
    

or with the as operator like this:

Manager m = (employee as Manager);
if (m != null)
{
    //do something with it
}

If anything is unclear i'llI'll be happy to correct it!

1: That is correct. When you do that you are casting it it into an "employee" object, so that means you cannot access anything manager specific.

2:

Downcasting is where you take a base class and then try and turn it into a more specific class. This can be accomplished with using is and an explicit cast like this:

if (employee is Manager)
{
    Manager m = (Manager)employee;
    //do something with it

}

or with the as operator like this:

Manager m = (employee as Manager);
if (m != null)
{
    //do something with it
}

If anything is unclear i'll be happy to correct it!

  1. That is correct. When you do that you are casting it it into an "employee" object, so that means you cannot access anything manager specific.

  2. Downcasting is where you take a base class and then try and turn it into a more specific class. This can be accomplished with using is and an explicit cast like this:

     if (employee is Manager)
     {
         Manager m = (Manager)employee;
         //do something with it
     }
    

or with the as operator like this:

Manager m = (employee as Manager);
if (m != null)
{
    //do something with it
}

If anything is unclear I'll be happy to correct it!

1: That is correct. When you do that you are casting it it into an "employee" object, so that means you cannot access anything manager specific.

2:

Downcasting is where you take a base class and then try and turn it into a more specific class. This can be accomplished with using is and an explicit cast like this:

if (employee is Manager)
{
    Manager m = (Manager)employee;
    //do something with it

}

or with the as operator like this:

Manager m = (employee as Manager);
if (managerm != null)
{
    //do something with it
}

If anything is unclear i'll be happy to correct it!

1: That is correct. When you do that you are casting it it into an "employee" object, so that means you cannot access anything manager specific.

2:

Downcasting is where you take a base class and then try and turn it into a more specific class. This can be accomplished with using is and an explicit cast like this:

if (employee is Manager)
{
    Manager m = (Manager)employee;
    //do something with it

}

or with the as operator like this:

Manager m = (employee as Manager);
if (manager != null)
{
    //do something with it
}

If anything is unclear i'll be happy to correct it!

1: That is correct. When you do that you are casting it it into an "employee" object, so that means you cannot access anything manager specific.

2:

Downcasting is where you take a base class and then try and turn it into a more specific class. This can be accomplished with using is and an explicit cast like this:

if (employee is Manager)
{
    Manager m = (Manager)employee;
    //do something with it

}

or with the as operator like this:

Manager m = (employee as Manager);
if (m != null)
{
    //do something with it
}

If anything is unclear i'll be happy to correct it!

added 162 characters in body; added 2 characters in body
Source Link
RCIX
  • 39.2k
  • 50
  • 151
  • 209
Loading
Source Link
RCIX
  • 39.2k
  • 50
  • 151
  • 209
Loading