How do i fix this error in c#

Ella McGillivray 26 Reputation points
2020-12-15T18:11:27.073+00:00

please Help me ASAP

48409-image.png

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,574 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Karen Payne MVP 35,291 Reputation points
    2020-12-15T20:18:00.993+00:00

    Hello @Ella McGillivray

    Would you please do the following

    • Post actual code rather than an image
    • Indicate what the issue is

    In the meantime all I can do is guess

    class Point  
    {  
        private int _p0;  
        private int _pl;  
        private Point P0;  
        private Point PI;  
        private decimal _slope;  
        private Point Pl;  
      
        public Point(int newP0, int newPl)  
        {  
            _p0 = newP0;  
            _pl = newPl;  
        }  
        public Point(int p0X, int p0Y, int plX, int plY)  
        {  
            P0 = new Point(p0X, p0Y);  
            PI = new Point(plX, plY);  
        }  
        public decimal Slope  
        {  
            get  
            {  
                _slope = (PI._p0 - P0._p0) / (Pl._p0 - P0._p0); return _slope;  
            }  
        }  
      
      
    }  
    

    Thanks


  2. Timon Yang-MSFT 9,576 Reputation points
    2020-12-16T01:56:32.833+00:00

    In combination with your other questions, I think you may be using the Point Struct provided by Microsoft right now, so you'd better not name your class "Point" at this time.

    When you create a Point instance inside your Point class, the compiler takes it for granted that you are creating your own Point instance, but based on the error, you seem to be creating the Microsoft Point struct, which caused an error.

    When we encounter errors caused by the same name, we generally use the full name of a class, like this:

            public System.Drawing.Point P0 { get; set; }  
            public Point()  
            {  
               P0 = new System.Drawing.Point(p0x,p0y);                 
            }  
    

    But that's because we can't make changes to those classes. For your current problem, I think it's better to change your class name.


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments