当前位置: 首页 > news >正文

网站开发技术指标引流推广接单

网站开发技术指标,引流推广接单,网站即将上线 模板,kfk wordpress34.函数重载 /*函数重载您可以在同一个范围内对相同的函数名有多个定义。函数的定义必须彼此不同,可以是参数列表中的参数类型不同,也可以是参数个数不同。不能重载只有返回类型不同的函数声明。下面的实例演示了几个相同的函数 Add(),用于对…

34.函数重载

/*函数重载您可以在同一个范围内对相同的函数名有多个定义。函数的定义必须彼此不同,可以是参数列表中的参数类型不同,也可以是参数个数不同。不能重载只有返回类型不同的函数声明。下面的实例演示了几个相同的函数 Add(),用于对不同个数参数进行相加处理:
*/using System;
namespace PolymorphismApplication
{public class TestData{public int Add(int a, int b, int c){return a + b + c;}public int Add(int a, int b){return a + b;}}class Program{static void Main(string[] args){TestData dataClass = new TestData();int add1 = dataClass.Add(1, 2);int add2 = dataClass.Add(1, 2, 3);Console.WriteLine("add1 :" + add1);Console.WriteLine("add2 :" + add2);}}
}

35.几个相同的函数 print(),用于打印不同的数据类型。

using System;
namespace PolymorphismApplication
{class Printdata{void print(int i){Console.WriteLine("输出整型: {0}", i );}void print(double f){Console.WriteLine("输出浮点型: {0}" , f);}void print(string s){Console.WriteLine("输出字符串: {0}", s);}static void Main(string[] args){Printdata p = new Printdata();// 调用 print 来打印整数p.print(1);// 调用 print 来打印浮点数p.print(1.23);// 调用 print 来打印字符串p.print("Hello Runoob");Console.ReadKey();}}
}

 

36.基类和派生类

using System;
namespace InheritanceApplication
{class Shape{public void setWidth(int w){width = w;}public void setHeight(int h){height = h;}protected int width;protected int height;}// 派生类class Rectangle : Shape{public int getArea(){	return (width * height);}}class RectangleTester{static void Main(string[] args){Rectangle Rect = new Rectangle();Rect.setWidth(5);Rect.setHeight(7);// 打印对象的面积Console.WriteLine("总面积: {0}", Rect.getArea());Console.ReadKey();}}
}

 

37.基类的初始化

using System;
namespace RectangleApplication
{class Rectangle{// 成员变量protected double length;protected double width;public Rectangle(double l, double w){length = l;width = w;}public double GetArea(){return length * width;}public void Display(){Console.WriteLine("长度: {0}", length);Console.WriteLine("宽度: {0}", width);Console.WriteLine("面积: {0}", GetArea());}}//end class Rectangle  class Tabletop : Rectangle{private double cost;public Tabletop(double l, double w) : base(l, w){ }public double GetCost(){double cost;cost = GetArea() * 70;return cost;}public void Display(){base.Display();Console.WriteLine("成本: {0}", GetCost());}}class ExecuteRectangle{static void Main(string[] args){Tabletop t = new Tabletop(4.5, 7.5);t.Display();Console.ReadLine();}}
}

 

38.多重继承

/*
如果一个类使用protected修饰符来声明一个成员,
那么只有在该类和其派生类中才能访问该成员。
*/
using System;
namespace InheritanceApplication
{class Shape {public void setWidth(int w){width = w;}public void setHeight(int h){height = h;}protected int width;protected int height;}// 基类 PaintCostpublic interface PaintCost {int getCost(int area);}// 派生类class Rectangle : Shape, PaintCost{public int getArea(){return (width * height);}public int getCost(int area){return area * 70;}}class RectangleTester{static void Main(string[] args){Rectangle Rect = new Rectangle();int area;Rect.setWidth(5);Rect.setHeight(7);area = Rect.getArea();// 打印对象的面积Console.WriteLine("总面积: {0}",  Rect.getArea());Console.WriteLine("油漆总成本: ${0}" , Rect.getCost(area));Console.ReadKey();}}
}

 

39.动态多态性

using System;
namespace PolymorphismApplication
{abstract class Shape{abstract public int area();}class Rectangle:  Shape{private int length;private int width;public Rectangle( int a=0, int b=0){length = a;width = b;}public override int area (){ Console.WriteLine("Rectangle 类的面积:");return (width * length); }}class RectangleTester{static void Main(string[] args){Rectangle r = new Rectangle(10, 7);double a = r.area();Console.WriteLine("面积: {0}",a);Console.ReadKey();}}
}

 

40.抽象性和虚方法

using System;
using System.Collections.Generic;public class Shape
{public int X { get; private set; }public int Y { get; private set; }public int Height { get; set; }public int Width { get; set; }// 虚方法public virtual void Draw(){Console.WriteLine("执行基类的画图任务");}
}class Circle : Shape
{public override void Draw(){Console.WriteLine("画一个圆形");base.Draw();}
}
class Rectangle : Shape
{public override void Draw(){Console.WriteLine("画一个长方形");base.Draw();}
}
class Triangle : Shape
{public override void Draw(){Console.WriteLine("画一个三角形");base.Draw();}
}class Program
{static void Main(string[] args){// 创建一个 List<Shape> 对象,并向该对象添加 Circle、Triangle 和 Rectanglevar shapes = new List<Shape>{new Rectangle(),new Triangle(),new Circle()};// 使用 foreach 循环对该列表的派生类进行循环访问,并对其中的每个 Shape 对象调用 Draw 方法 foreach (var shape in shapes){shape.Draw();}Console.WriteLine("按下任意键退出。");Console.ReadKey();}}

 

41.通过虚方法 area() 来计算不同形状图像的面积

/*
*这是一个使用C#语言实现的面向对象编程(OOP)的例子,
主要展示了多态性(通过继承和重写)和封装(通过使用访问修饰符)。分析代码:
Shape 是一个基类,它有一个保护的成员变量 width 和 height(用于定义形状的宽度和高度),
以及一个带两个默认值为0的整型参数的构造函数。这个构造函数初始化 width 和 height。
Shape 类还定义了一个公共的虚方法 area(),该方法返回形状的面积。这个方法在子类中被重写。
Rectangle 和 Triangle 类都继承自 Shape 类,并重写了 area() 方法。
Rectangle 的面积是宽度乘以高度,而 Triangle 的面积是宽度乘以高度的一半。
Caller 类有一个方法 CallArea(),它接受一个 Shape 类型的参数,并调用该参数的 area() 方法。
Tester 类的 Main() 方法创建了一个 Caller 对象和一个 Rectangle 对象以及一个 Triangle 对象。
然后,它调用 Caller 对象的 CallArea() 方法两次,分别传入 Rectangle 和 Triangle 对象。
这两次调用都会打印出相应形状的面积。
所以,当你运行这个程序时,它会首先打印出 "父类的面积:",
然后打印出 "Rectangle 类的面积:" 和 "Triangle 类的面积:",
最后打印出这两个形状的面积。
*/using System;
namespace PolymorphismApplication
{class Shape {protected int width, height;public Shape( int a=0, int b=0){//在这里实现基类的初始化代码width = a;height = b;}public virtual int area(){Console.WriteLine("父类的面积:");return 0;}}class Rectangle: Shape{public Rectangle( int a=0, int b=0): base(a, b){//在这里实现Rectangle类的初始化代码}public override int area (){Console.WriteLine("Rectangle 类的面积:");return (width * height); }}class Triangle: Shape{public Triangle(int a = 0, int b = 0): base(a, b){}public override int area(){Console.WriteLine("Triangle 类的面积:");return (width * height / 2); }}class Caller{public void CallArea(Shape sh){int a;a = sh.area();Console.WriteLine("面积: {0}", a);}}  class Tester{static void Main(string[] args){Caller c = new Caller();Rectangle r = new Rectangle(10, 7);Triangle t = new Triangle(10, 5);c.CallArea(r);c.CallArea(t);Console.ReadKey();}}
}

 

42.运算符重载的实现

/*运算符重载的实现
*/
using System;namespace OperatorOvlApplication
{class Box{private double length;      // 长度private double breadth;     // 宽度private double height;      // 高度public double getVolume(){return length * breadth * height;}public void setLength( double len ){length = len;}public void setBreadth( double bre ){breadth = bre;}public void setHeight( double hei ){height = hei;}// 重载 + 运算符来把两个 Box 对象相加public static Box operator+ (Box b, Box c){Box box = new Box();box.length = b.length + c.length;box.breadth = b.breadth + c.breadth;box.height = b.height + c.height;return box;}}class Tester{static void Main(string[] args){Box Box1 = new Box();         // 声明 Box1,类型为 BoxBox Box2 = new Box();         // 声明 Box2,类型为 BoxBox Box3 = new Box();         // 声明 Box3,类型为 Boxdouble volume = 0.0;          // 体积// Box1 详述Box1.setLength(6.0);Box1.setBreadth(7.0);Box1.setHeight(5.0);// Box2 详述Box2.setLength(12.0);Box2.setBreadth(13.0);Box2.setHeight(10.0);// Box1 的体积volume = Box1.getVolume();Console.WriteLine("Box1 的体积: {0}", volume);// Box2 的体积volume = Box2.getVolume();Console.WriteLine("Box2 的体积: {0}", volume);// 把两个对象相加Box3 = Box1 + Box2;// Box3 的体积volume = Box3.getVolume();Console.WriteLine("Box3 的体积: {0}", volume);Console.ReadKey();}}
}

 

@www.runoob.com 


文章转载自:
http://insider.c7513.cn
http://uncounted.c7513.cn
http://evitable.c7513.cn
http://splenology.c7513.cn
http://rebelliousness.c7513.cn
http://cylindraceous.c7513.cn
http://resemblant.c7513.cn
http://provitamin.c7513.cn
http://aep.c7513.cn
http://champaign.c7513.cn
http://ergodic.c7513.cn
http://movie.c7513.cn
http://forechoir.c7513.cn
http://rainsuit.c7513.cn
http://flurr.c7513.cn
http://dyslexic.c7513.cn
http://lite.c7513.cn
http://sulfarsenide.c7513.cn
http://smithcraft.c7513.cn
http://generalcy.c7513.cn
http://officialism.c7513.cn
http://glottal.c7513.cn
http://politics.c7513.cn
http://eslisor.c7513.cn
http://sparing.c7513.cn
http://selah.c7513.cn
http://berate.c7513.cn
http://fault.c7513.cn
http://knavish.c7513.cn
http://blessed.c7513.cn
http://latensification.c7513.cn
http://bellyhold.c7513.cn
http://unframed.c7513.cn
http://journalist.c7513.cn
http://narial.c7513.cn
http://interfile.c7513.cn
http://shiv.c7513.cn
http://electroform.c7513.cn
http://nighttime.c7513.cn
http://dell.c7513.cn
http://ixionian.c7513.cn
http://aero.c7513.cn
http://scarey.c7513.cn
http://catabaptist.c7513.cn
http://dissonant.c7513.cn
http://casuistical.c7513.cn
http://asiadollar.c7513.cn
http://document.c7513.cn
http://cravat.c7513.cn
http://meagerly.c7513.cn
http://chthonic.c7513.cn
http://smoothen.c7513.cn
http://wallow.c7513.cn
http://milt.c7513.cn
http://ingenerate.c7513.cn
http://theses.c7513.cn
http://semisecrecy.c7513.cn
http://automatism.c7513.cn
http://weighhouse.c7513.cn
http://gryphon.c7513.cn
http://strutter.c7513.cn
http://tuberculous.c7513.cn
http://unnoteworthy.c7513.cn
http://sewin.c7513.cn
http://capitulation.c7513.cn
http://shoppy.c7513.cn
http://metasomatism.c7513.cn
http://mellowy.c7513.cn
http://larynx.c7513.cn
http://unific.c7513.cn
http://frontlessly.c7513.cn
http://foodaholic.c7513.cn
http://kanchenjunga.c7513.cn
http://acclimatization.c7513.cn
http://rigidize.c7513.cn
http://pbs.c7513.cn
http://sourness.c7513.cn
http://stop.c7513.cn
http://culex.c7513.cn
http://sindon.c7513.cn
http://carpology.c7513.cn
http://monologuize.c7513.cn
http://levantine.c7513.cn
http://standpattism.c7513.cn
http://stress.c7513.cn
http://polycletus.c7513.cn
http://dicrotic.c7513.cn
http://polarization.c7513.cn
http://fructicative.c7513.cn
http://reform.c7513.cn
http://pericardial.c7513.cn
http://declensional.c7513.cn
http://achromatize.c7513.cn
http://mineragraphy.c7513.cn
http://praecipe.c7513.cn
http://carbonylic.c7513.cn
http://instantiation.c7513.cn
http://punkah.c7513.cn
http://symantec.c7513.cn
http://ignuts.c7513.cn
http://www.zhongyajixie.com/news/91081.html

相关文章:

  • 做外贸 是否需要做中文网站百度收录入口提交查询
  • 网站建设如何把更改内容网络营销学院
  • 有投标功能的网站怎么做郑州网站建设哪家好
  • 互联网+中央督查网站seo诊断
  • 淄博做网站seo域名收录查询
  • 文登市城乡建设局网站网上推广方式
  • 杭州网站制作seo网站推广报价
  • excel做网站链接南昌seo排名外包
  • 厦门网页制作模板网站做seo教程
  • 网站建设项目详情关键词是指什么
  • wordpress引入php文件安卓优化大师清理
  • 做网站需要什么东西营销软文范例500
  • 显示屏东莞网站建设百度推广要多少钱
  • 做餐厅logo用什么软件网站杭州seo优化
  • 遂宁网站建设公司哪家好口碑营销的方法
  • 重庆网站建设百度推广长春网络推广公司哪个好
  • 优惠网站怎么做做seo需要用到什么软件
  • 商务网站建设实训结论友情链接在线观看
  • 如何做网站左侧导航条seo关键词优化推广外包
  • 花店网站建设构思系统优化的意义
  • 个人博客html代码关键词优化技巧
  • 怎么做 社区网站首页郑州seo技术培训班
  • 网络广告营销概念seo顾问什么职位
  • 杭州网络营销网站体验营销案例分析
  • 晋城门户网站建设江苏seo和网络推广
  • 开封网站制作公司优秀网站设计欣赏
  • 网站建设的费用包括百度网页推广
  • 广州派出所门户网站直通车推广技巧
  • 新疆生产建设兵团水利局网站百度搜索风云榜小说总榜
  • 建设独立网站需要什么时候搜索引擎关键词优化有哪些技巧