By Hubaka Gs


2019-09-11 09:09:57 8 Comments

I want to access x values from a Point from an array from a method parameter, but I get the error "'Point.x' is inaccessible due to its protection level"

I've tried to add and change the Point array and set it to public, but I got even more errors.

int findMeetingPlace(Point[] houseLocations, Point kakekHouse, int D)
{
    int i;
    int j;
    float xdisttoroot;
    float housedistx;
    float housedisty;
    float[] currenthousedist;
    int houseLlength = houseLocations.Length;

    for(i=0;i<=houseLlength;i++)
    {
        for(j=0;j<=houseLlength;j++)
        {
            if(i!=j)
                housedistx = houseLocations[i].x - houseLocations[j].x ;
        }
    }

    return (int)Math.Round(housedistx);
}

I expect the output to be housedistx int, but I get the said error at the 13th line.

1 comments

@Raka 2019-09-11 09:13:22

You need to use X (capital x), small x is private and cannot be accessed.

@Lasse Vågsæther Karlsen 2019-09-11 09:19:01

This is almost certainly the right answer. The x identifier is for the private field, aka private TYPE x;, and the X identifier is for the public property, aka public TYPE X { get { return this.x; } set { this.x = value; } }.

Related Questions

Sponsored Content

34 Answered Questions

35 Answered Questions

[SOLVED] Create ArrayList from array

82 Answered Questions

[SOLVED] How do I remove a particular element from an array in JavaScript?

  • 2011-04-23 22:17:18
  • Walker
  • 5952169 View
  • 7420 Score
  • 82 Answer
  • Tags:   javascript arrays

37 Answered Questions

[SOLVED] Deleting an element from an array in PHP

  • 2008-12-15 20:28:55
  • Ben
  • 2371695 View
  • 2314 Score
  • 37 Answer
  • Tags:   php arrays unset

26 Answered Questions

[SOLVED] Why not inherit from List<T>?

32 Answered Questions

[SOLVED] What's the simplest way to print a Java array?

  • 2009-01-03 20:39:39
  • Alex Spurling
  • 2089561 View
  • 1803 Score
  • 32 Answer
  • Tags:   java arrays printing

27 Answered Questions

[SOLVED] What is the best way to iterate over a dictionary?

  • 2008-09-26 18:20:06
  • Jake Stewart
  • 1428862 View
  • 2369 Score
  • 27 Answer
  • Tags:   c# dictionary loops

5 Answered Questions

[SOLVED] Is there a reason for C#'s reuse of the variable in a foreach?

5 Answered Questions

[SOLVED] How do I use arrays in C++?

Sponsored Content