C# Language Specification



Download 0,75 Mb.
bet513/524
Sana06.01.2022
Hajmi0,75 Mb.
#324842
1   ...   509   510   511   512   513   514   515   516   ...   524
Bog'liq
CSharp Language Specification

An example

  • C# source code


    The following example shows the source code of a Point class:

    namespace Graphics


    {

    ///

    Class Point models a point in a two-dimensional plane.


    ///

    public class Point
    {

    ///

    Instance variable x represents the point's


    /// x-coordinate.

    private int x;

    ///

    Instance variable y represents the point's


    /// y-coordinate.

    private int y;

    /// Property X represents the point's x-coordinate.


    public int X
    {
    get { return x; }
    set { x = value; }
    }

    /// Property Y represents the point's y-coordinate.


    public int Y
    {
    get { return y; }
    set { y = value; }
    }

    ///

    This constructor initializes the new Point to


    /// (0,0).

    public Point() : this(0,0) {}

    ///

    This constructor initializes the new Point to


    /// (
    ,
    ).

    ///
    xor is the new Point's x-coordinate.

    ///
    yor is the new Point's y-coordinate.

    public Point(int xor, int yor) {
    X = xor;
    Y = yor;
    }

    ///

    This method changes the point's location to


    /// the given coordinates.

    ///
    xor is the new x-coordinate.

    ///
    yor is the new y-coordinate.

    ///
    public void Move(int xor, int yor) {
    X = xor;
    Y = yor;
    }

    ///

    This method changes the point's location by


    /// the given x- and y-offsets.
    /// For example:
    ///
    /// Point p = new Point(3,5);
    /// p.Translate(-1,3);
    ///

    /// results in p's having the value (2,8).
    ///

    ///

    ///
    xor is the relative x-offset.

    ///
    yor is the relative y-offset.

    ///
    public void Translate(int xor, int yor) {
    X += xor;
    Y += yor;
    }

    ///

    This method determines whether two Points have the same


    /// location.

    ///
    o is the object to be compared to the current object.
    ///

    /// True if the Points have the same location and they have


    /// the exact same type; otherwise, false.
    ///
    ///
    public override bool Equals(object o) {
    if (o == null) {
    return false;
    }

    if (this == o) {


    return true;
    }

    if (GetType() == o.GetType()) {


    Point p = (Point)o;
    return (X == p.X) && (Y == p.Y);
    }
    return false;
    }

    ///

    Report a point's location as a string.


    /// A string representing a point's location, in the form (x,y),
    /// without any leading, training, or embedded whitespace.

    public override string ToString() {
    return "(" + X + "," + Y + ")";
    }

    ///

    This operator determines whether two Points have the same


    /// location.

    ///
    p1 is the first Point to be compared.

    ///
    p2 is the second Point to be compared.

    /// True if the Points have the same location and they have
    /// the exact same type; otherwise, false.

    ///
    ///
    public static bool operator==(Point p1, Point p2) {
    if ((object)p1 == null || (object)p2 == null) {
    return false;
    }

    if (p1.GetType() == p2.GetType()) {


    return (p1.X == p2.X) && (p1.Y == p2.Y);
    }

    return false;


    }

    ///

    This operator determines whether two Points have the same


    /// location.

    ///
    p1 is the first Point to be compared.

    ///
    p2 is the second Point to be compared.

    /// True if the Points do not have the same location and the
    /// exact same type; otherwise, false.

    ///
    ///
    public static bool operator!=(Point p1, Point p2) {
    return !(p1 == p2);
    }

    ///

    This is the entry point of the Point class testing


    /// program.
    ///
    This program tests each method and operator, and
    /// is intended to be run after any non-trvial maintenance has
    /// been performed on the Point class.

    public static void Main() {
    // class test code goes here
    }
    }
    }

    1. Download 0,75 Mb.

      Do'stlaringiz bilan baham:
  • 1   ...   509   510   511   512   513   514   515   516   ...   524




    Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
    ma'muriyatiga murojaat qiling

    kiriting | ro'yxatdan o'tish
        Bosh sahifa
    юртда тантана
    Боғда битган
    Бугун юртда
    Эшитганлар жилманглар
    Эшитмадим деманглар
    битган бодомлар
    Yangiariq tumani
    qitish marakazi
    Raqamli texnologiyalar
    ilishida muhokamadan
    tasdiqqa tavsiya
    tavsiya etilgan
    iqtisodiyot kafedrasi
    steiermarkischen landesregierung
    asarlaringizni yuboring
    o'zingizning asarlaringizni
    Iltimos faqat
    faqat o'zingizning
    steierm rkischen
    landesregierung fachabteilung
    rkischen landesregierung
    hamshira loyihasi
    loyihasi mavsum
    faolyatining oqibatlari
    asosiy adabiyotlar
    fakulteti ahborot
    ahborot havfsizligi
    havfsizligi kafedrasi
    fanidan bo’yicha
    fakulteti iqtisodiyot
    boshqaruv fakulteti
    chiqarishda boshqaruv
    ishlab chiqarishda
    iqtisodiyot fakultet
    multiservis tarmoqlari
    fanidan asosiy
    Uzbek fanidan
    mavzulari potok
    asosidagi multiservis
    'aliyyil a'ziym
    billahil 'aliyyil
    illaa billahil
    quvvata illaa
    falah' deganida
    Kompyuter savodxonligi
    bo’yicha mustaqil
    'alal falah'
    Hayya 'alal
    'alas soloh
    Hayya 'alas
    mavsum boyicha


    yuklab olish