zoukankan      html  css  js  c++  java
  • c#笔记2019-01-06

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    /*2019-01-06C#学习笔记-封装修饰词
    * Public 
    * Private
    */
    namespace Csharp_study
    {
    //1.public封装修饰词-公共
    class TestPublic
    { 
    //成员变量height高、width宽
    public double height;
    public double width;
    //成员方法
    public double getArea(double height,double width) {
    return (height * width);
    }
    }
    
    //2.Private封装修饰词-私有只能在本类中使用
    class TestPrivate 
    {
    //成员变量-私有
    private double Redio;
    //成员方法-私有
    private double getArea(double canshu)
    {
    return canshu * canshu * 3.14;
    }
    //成员方法-公共
    public double getAreaPB()
    {
    //同一类内可以调用private成员变量
    Redio = 2.1;
    //同一类内可以调用private成员方法
    return getArea(Redio);
    }
    }
    
    class section3
    {
    static void Main(string[] args){
    
    //TestPublic实例
    TestPublic ts = new TestPublic();
    //使用TestPublic类的public成员变量
    ts.height = 2.1;
    ts.width = 3.0;
    double Area;
    //调用TestPublic类的public成员方法
    Area=ts.getArea(ts.height, ts.width);
    Console.WriteLine("heigth:{0},{1},area:{2}", ts.height, ts.width, Area);
    
    //TestPrivate实例
    TestPrivate tp = new TestPrivate();
    //tp.Redio = 2.1;//在不同类中无法访问Private声明的成员对象
    //tp.getArea(2.1);//在不同类中无法访问Private声明的成员方法
    Console.WriteLine("area2:{0}",tp.getAreaPB());
    
    
    Console.ReadKey();
    }
    }
    }
    

      

  • 相关阅读:
    如何理解volatile关键字
    Spring 4+JMS+ActiveMQ Example with Annotations
    Spring MVC如何获得客户端IP地址
    PDFBox –如何读取PDF的内容
    Spring MVC 使用Ehcache作为缓存的例子
    自定义了一个data table控件
    Linux基本配置
    位操作学习
    QT——QPainter类详解
    QT——设计文件的和控制类的关联问题
  • 原文地址:https://www.cnblogs.com/soulsjie/p/10229067.html
Copyright © 2011-2022 走看看