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