38
Лекц №6 КЛАСС БА ОБЪЕКТ

Лекц 6 - 7

Embed Size (px)

Citation preview

  • 1. 6

2. : 3. - . . 4. [attributes] [modifiers] class identifier [:baselist] {class body} 5. . : . . [ClassDesc(Author="Knuth"), ClassDesc(Author="Ja mes")] 6. , , . internal . 7. public .protected . .internal .private . . 8. . const . . . 9. using System; class Conversions { public const double Cm = 2.54; public const double Grams = 454.0 , km = .62 ; public const string ProjectName = "Metrics"; } 10. class ShowConversions{ static void Main() { double pounds, gramWeight; gramWeight = 1362; pounds = gramWeight / Conversions.Grams; Console.WriteLine("{0} Grams= Pounds", gramWeight,pounds); Console.WriteLine("Cm per inch {0}", Conversions.Cm); Conversions c= new Conversions(); // Create class // This fails to compile. Cannot access const from object Console.WriteLine("Cm per inch {0}", c.Cm); } }{1} 11. . static .readonly . 12. public class Upholstery{ public static readonly Upholstery silk = new Upholstery(15.00, 8); public static readonly Upholstery wool = new Upholstery(12.00, 6); public static readonly Upholstery cotton = new Upholstery(9.00, 6); private double yardPrice; private int deliveryWeeks; private Upholstery ( double yrPrice, int delWeeks) { yardPrice = yrPrice; deliveryWeeks = delWeeks; } 13. public double FabCost(double yards) { return yards * this.yardPrice; } public int DeliveryTime {get { return deliveryWeeks;}} public double PricePerYard {get {return yardPrice;}} } 14. . .: [attributes] { [access modifier] get { ... return(propertyvalue) } [access modifier] set { ... Code to set a field to the keyword value } } 15. Value Get . . Set . . 16. public class Upholstery { private double yardPrice; public double PricePerYard { get {return yardPrice;} set { if ( value