Как создать объект класса, если в нем реализована перегрузка? - C#

Узнай цену своей работы

Формулировка задачи:

Есть код:
Листинг программы
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace thevector
  6. {
  7. class Vector
  8. {
  9. double x, y, z;
  10. public Vector(double x, double z, double y)
  11. {
  12. this.x = x;
  13. this.y = y;
  14. this.z = z;
  15. }
  16.  
  17. public static Vector operator +(Vector a, Vector b)
  18. {
  19. Vector c = new Vector(a.x + b.x, a.y + b.y, a.z + b.z); //результирующий вектор
  20. return c;
  21. }
  22. public void setVectorPos()
  23. {
  24. Console.WriteLine("Enter x:");
  25. this.x = Int32.Parse(Console.ReadLine());
  26. Console.WriteLine("Enter y:");
  27. this.y = Int32.Parse(Console.ReadLine());
  28. Console.WriteLine("Enter z:");
  29. this.z = Int32.Parse(Console.ReadLine());
  30. }
  31. public void getVectorPos() {
  32. Console.WriteLine("Vector Coordinates:" + "x " + this.x + "y " + this.y + "z " + this.z);
  33. }
  34. public void sumOfVectors()
  35. {
  36. Console.WriteLine("set First Coordinates: ");
  37. setVectorPos();
  38. Vector a = new Vector(x, y, z);
  39. Console.WriteLine("set Second Coordinates: ");
  40. setVectorPos();
  41. Vector b = new Vector(x, y, z);
  42. Vector c = a + b;
  43. getVectorPos();
  44. }
  45. }
  46. class Program : Vector {
  47. static void Main()
  48. {
  49. Vector vec;
  50. int point = 0;
  51. string taker;
  52. Console.WriteLine("Select to do:");
  53. Console.WriteLine("set - set vector position");
  54. Console.WriteLine("get - get vector position:");
  55. Console.WriteLine("sum - take a sum of 2 vectors");
  56. while (point == 0)
  57. {
  58. taker = Console.ReadLine();
  59. if ("set".Equals(taker)) { }
  60. }
  61. }
  62. }
  63. }
Как в нем создать объект? Не могу его создать ввиду того что он сразу воспринимается как метод класса. Как быть?

Решение задачи: «Как создать объект класса, если в нем реализована перегрузка?»

textual
Листинг программы
  1. Vector vec = new Vector(0.5, 0.5, 0.5);

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

7   голосов , оценка 3.714 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут
Похожие ответы