Advertisement
zsoltizbekk

2016.03.01_c#...

Mar 1st, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.30 KB | None | 0 0
  1. //Program.cs
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using geom;
  9.  
  10. namespace ConsoleApplication1
  11. {
  12.     class Program
  13.     {
  14.         static void Main(string[] args)
  15.         {
  16.             Console.WriteLine("hello");
  17.             Pont p1 = new Pont(4, 5, "fekete");
  18.             Console.WriteLine("({0}, {1})", p1.X, p1.Y);
  19.             //###
  20.             //Console.WriteLine("({0}, {1})", p1.getX(), p1.getY());
  21.             //p1.setX(-3);
  22.             //Console.WriteLine("({0}, {1})", p1.getX(), p1.getY());
  23.             Pont p2 = new Pont();
  24.             //Console.WriteLine("({0}, {1}), {2}", p1.X, p1.Y, p1.Szin);
  25.             //p1.X = -3
  26.  
  27.             Console.WriteLine("({0}, {1}), {2}", p1.X, p1.Y, p1.Szin);
  28.             Console.WriteLine(p1.ToString());
  29.             Console.WriteLine(p2);
  30.  
  31.             Pont p3 = new Pont();
  32.             if (p2.Equals(p3))
  33.                 Console.WriteLine("egyenlő");
  34.             else
  35.                 Console.WriteLine("nem egyenlő");
  36.             Console.WriteLine("{0,5}, {1,-6:F1}{2}", "alma", 4.56, 'x');
  37.             string sor = Console.ReadLine();
  38.             int x = int.Parse(sor);
  39.             Console.WriteLine(x);
  40.         }
  41.     }
  42. }
  43.  
  44. //Class1.cs
  45.  
  46. using System;
  47. using System.Collections.Generic;
  48. using System.Linq;
  49. using System.Text;
  50. using System.Threading.Tasks;
  51.  
  52. namespace geom
  53. {
  54.     class Pont
  55.     {
  56.         private int x, y;
  57.         public int X
  58.         {
  59.             get
  60.             {
  61.                 return x;
  62.             }
  63.             set
  64.             {
  65.                 x = value;
  66.             }
  67.         }
  68.  
  69.         public int Y
  70.         {
  71.             get
  72.             {
  73.                 return y;
  74.             }
  75.             set
  76.             {
  77.                 y = value;
  78.             }
  79.         }
  80.         public string Szin { get; private set; }
  81.  
  82.         public Pont(int x, int y, string szin)
  83.         {
  84.             this.x = x;
  85.             this.y = y;
  86.             Szin = szin;
  87.         }
  88.  
  89.         public Pont(int x, int y) : this(x, y, "feher")
  90.         {
  91.         }
  92.  
  93.         public Pont() : this(0, 0)
  94.         {
  95.         }
  96.         //public int getX()
  97.         //{
  98.         //    return x;
  99.         //}
  100.  
  101.         //public int getY()
  102.         //{
  103.         //    return y;
  104.         //}
  105.  
  106.         //public void setX(int x)
  107.         //{
  108.         //    this.x = x;
  109.         //}
  110.         //public void setY(int y)
  111.         //{
  112.         //    this.y = y;
  113.         //}
  114.  
  115.         public override string ToString()
  116.         {
  117.             return "(" + x + ", " + y + ")" + Szin;
  118.         }
  119.  
  120.         public override bool Equals(object obj)
  121.         {
  122.             Pont other = obj as Pont; //0-at ad vissza ha nem ugyanolyan tipusu
  123.             return other != null && x == other.x && y == other.y && Szin.Equals(other.Szin); // szin-hez is mehet == Equals helyett
  124.  
  125.             //if (obj == null)
  126.             //    return false;
  127.             //if (!(obj is Pont))
  128.             //    return false;
  129.             //Pont other = (Pont)obj;
  130.             //if (x != other.x)
  131.             //    return false;
  132.             //if (y != other.y)
  133.             //    return false;
  134.             //if (!Szin.Equals(other.Szin))
  135.             //    return false;
  136.             //return true;
  137.         }
  138.     }
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement