C
C#•3y ago
lia

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
becquerel•3y ago
need to explain your problem before anyone can help
lia
liaOP•3y ago
can i sharescreen my code on a call? i dont know how to explain it
becquerel
becquerel•3y ago
no if you can explain it on a call, you can explain it over ironic
lia
liaOP•3y ago
i just want to show my code not talk
becquerel
becquerel•3y ago
$code
MODiX
MODiX•3y 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/
lia
liaOP•3y ago
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
becquerel•3y ago
ok how does it not work
lia
liaOP•3y ago
idk it just syd error
becquerel
becquerel•3y ago
what's the error
lia
liaOP•3y ago
"Cannot convert method group 'GetX' to non delegate type 'Double'
becquerel
becquerel•3y 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()?
lia
liaOP•3y ago
ya
becquerel
becquerel•3y ago
do you see a difference between those and this.x = another.GetX;?
lia
liaOP•3y ago
no i need two x's
becquerel
becquerel•3y 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
lia
liaOP•3y ago
i know i want that tho
becquerel
becquerel•3y 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?
lia
liaOP•3y ago
yes
becquerel
becquerel•3y ago
but that's not working 😛
lia
liaOP•3y ago
yes that the problem? is* when i remove the () it make more errors
becquerel
becquerel•3y ago
yes... so you want to add the ()
lia
liaOP•3y ago
i did
becquerel
becquerel•3y ago
and?
lia
liaOP•3y ago
so instead of getX i do GetX() ?
becquerel
becquerel•3y ago
yes
lia
liaOP•3y ago
ok thank you
lia
liaOP•3y ago
if i do GetX in another part of the code will it be the same GetX as the last one?
becquerel
becquerel•3y 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
lia
liaOP•3y ago
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
becquerel•3y ago
you don't have to put a new x in anywhere when you call another.GetX()?
lia
liaOP•3y ago
thats the question yes
becquerel
becquerel•3y ago
i don't understand your question - maybe give two examples of what you mean, one with 'putting in the X' and one without
lia
liaOP•3y ago
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
becquerel•3y ago
i really don't know what you mean by 'put the x' are you thinking you could just write .Get() or something?
lia
liaOP•3y ago
no no, sorry english isnt my first language idk how to explain it
becquerel
becquerel•3y ago
fair enough, it's difficult do you mean the fact that there are two xs in this.x + another.GetX()?
lia
liaOP•3y ago
uhhhh no I don’t think so it’s probably nothing thank you

Did you find this page helpful?