Hi i need some help with classes, im pretty new to this and i have an error with my code.

help would be appreciated(in csharp)
40 Replies
becquerel
becquerel3y ago
need to explain your problem before anyone can help
חגית שמעוני
can i sharescreen my code on a call? i dont know how to explain it
becquerel
becquerel3y ago
no if you can explain it on a call, you can explain it over ironic
חגית שמעוני
i just want to show my code not talk
becquerel
becquerel3y ago
$code
MODiX
MODiX3y ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat If your code is too long, post it to: https://paste.mod.gg/
חגית שמעוני
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Point
{
class Point
{
private double x;
private double y;

public Point()
{
}
public Point(double x, double y)
{
this.x = x;
this.y = y;
}
public Point(Point another)
{
this.x = another.GetX;
this.y = another.GetY;
}
public double distanceToPoint(Point another)
{
double dis = Math.Sqrt(Math.Pow(this.x - another.GetX(), 2) + Math.Pow(this.y - another.GetY(), 2));
return dis;
}
public override string ToString()
{
return "("+this.x+","+this.y+")";
}
public double GetX()
{
return this.x;
}
public double GetY()
{
return this.y;
}
public void SetX(double x)
{
this.x = x;
}
public void SetY(double x)
{
this.y = y;
}

static void Main(string[] args)
{
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Point
{
class Point
{
private double x;
private double y;

public Point()
{
}
public Point(double x, double y)
{
this.x = x;
this.y = y;
}
public Point(Point another)
{
this.x = another.GetX;
this.y = another.GetY;
}
public double distanceToPoint(Point another)
{
double dis = Math.Sqrt(Math.Pow(this.x - another.GetX(), 2) + Math.Pow(this.y - another.GetY(), 2));
return dis;
}
public override string ToString()
{
return "("+this.x+","+this.y+")";
}
public double GetX()
{
return this.x;
}
public double GetY()
{
return this.y;
}
public void SetX(double x)
{
this.x = x;
}
public void SetY(double x)
{
this.y = y;
}

static void Main(string[] args)
{
}
}
}
public Point(Point another) { this.x = another.GetX; this.y = another.GetY; } this part doesnt work
becquerel
becquerel3y ago
ok how does it not work
חגית שמעוני
idk it just syd error
becquerel
becquerel3y ago
what's the error
חגית שמעוני
"Cannot convert method group 'GetX' to non delegate type 'Double'
becquerel
becquerel3y ago
ok you see how in this line: double dis = Math.Sqrt(Math.Pow(this.x - another.GetX(), 2) + Math.Pow(this.y - another.GetY(), 2)); you're doing another.GetX() and another.GetY()?
becquerel
becquerel3y ago
do you see a difference between those and this.x = another.GetX;?
חגית שמעוני
no i need two x's
becquerel
becquerel3y ago
the difference is the () after GetX if you just have GetX, that's the name of the function if you have GetX(), that's calling the function to make it do something and give you a result
חגית שמעוני
i know i want that tho
becquerel
becquerel3y ago
in
public Point(Point another)
{
this.x = another.GetX;
this.y = another.GetY;
}
public Point(Point another)
{
this.x = another.GetX;
this.y = another.GetY;
}
? are you sure?
חגית שמעוני
yes
becquerel
becquerel3y ago
but that's not working 😛
חגית שמעוני
yes that the problem? is* when i remove the () it make more errors
becquerel
becquerel3y ago
yes... so you want to add the ()
חגית שמעוני
i did
becquerel
becquerel3y ago
and?
חגית שמעוני
so instead of getX i do GetX() ?
becquerel
becquerel3y ago
yes
חגית שמעוני
ok thank you
חגית שמעוני
if i do GetX in another part of the code will it be the same GetX as the last one?
becquerel
becquerel3y ago
explain what you mean in a bit more detail please it will call the same function, but the object it calls it on may be different
חגית שמעוני
does the user need to put the X in the function twice? i mean, whenever i call the function does the user need to put a new X again?
becquerel
becquerel3y ago
you don't have to put a new x in anywhere when you call another.GetX()?
חגית שמעוני
thats the question yes
becquerel
becquerel3y ago
i don't understand your question - maybe give two examples of what you mean, one with 'putting in the X' and one without
חגית שמעוני
cs public double distanceToPoint(Point another)
{
double dis = Math.Sqrt(Math.Pow(this.x - another.GetX(), 2) + Math.Pow(this.y - another.GetY(), 2));
return dis;
}
public double ThirdPoint(Point another)
{
double pthreeX = (this.x + another.GetX()) / 2;
double pthreeY = (this.y + another.GetY()) / 2;
return (pthreeX, pthreeY);
}
cs public double distanceToPoint(Point another)
{
double dis = Math.Sqrt(Math.Pow(this.x - another.GetX(), 2) + Math.Pow(this.y - another.GetY(), 2));
return dis;
}
public double ThirdPoint(Point another)
{
double pthreeX = (this.x + another.GetX()) / 2;
double pthreeY = (this.y + another.GetY()) / 2;
return (pthreeX, pthreeY);
}
it calls the function twice but do i need to put the x twice too?
becquerel
becquerel3y ago
i really don't know what you mean by 'put the x' are you thinking you could just write .Get() or something?
חגית שמעוני
no no, sorry english isnt my first language idk how to explain it
becquerel
becquerel3y ago
fair enough, it's difficult do you mean the fact that there are two xs in this.x + another.GetX()?
חגית שמעוני
uhhhh no I don’t think so it’s probably nothing thank you

Did you find this page helpful?