Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8815571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:24:46+00:00 2026-06-14T04:24:46+00:00

private Vector2 ResolveCollision(ICollidable moving, ICollidable stationary) { if (moving.Bounds.Intersects(stationary.Bounds)) { if (moving is Player)

  • 0
private Vector2 ResolveCollision(ICollidable moving, ICollidable stationary)
{
    if (moving.Bounds.Intersects(stationary.Bounds))
    {
        if (moving is Player)
        {
            (Player)moving.Color = Color.Red;
        }
    }
    // ...
}

I have a class Player that implements ICollidable. For debugging purposes I’m just trying to pass a bunch of ICollidables to this method and do some special stuff when it’s the player. However when I try to do the cast to Player of the ICollidable I get an error telling me that ICollidable doesn’t have a Color property.

Am I not able to make a cast this way or am I doing something wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T04:24:47+00:00Added an answer on June 14, 2026 at 4:24 am

    I’d suggest using as instead of is:

    Player player = moving as Player;
    if (player != null)
    {
        player.Color = Color.Red;
    }
    

    The advantage is that you only do the type check once.


    The specific reason why your code doesn’t work (as mentioned in other answers) is because of operator precedence. The . operator is a primary operator which has a higher precedence than the casting operator which is a unary operator. Your code is interpreted as follows:

    (Player)(moving.Color) = Color.Red;
    

    Adding the parentheses as suggested by other answers solves this issue, but changing to use as instead of is makes the issue go away completely.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have: class Test { private Vector2 v; public Vector2 Velocity { get
I have this: public class DoubleList<Key, Elem> implements ADTDoubleList<Key, Elem> { private Vector<Node<Key, Elem>>
I have the following class: import java.awt.Color; import java.util.Vector; public class MyClass { private
I will first illustrate my issue with some code: class ExampleClass { private Vector2
I have a class which has a private attribute vector rectVec; class A {
suppose you have two (or more) classes with private member vectors: class A {
I have these classes: class Base { ... private: std::vector<X> v; }; class Derived
I have a class with a private vector of doubles. To access or modify
I have the following in my Puzzle.h class Puzzle { private: vector<int> puzzle; public:
suppose I have the following class: class MyInteger { private: int n_; public: MyInteger(int

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.