C
C#2y ago
avishy

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