Description:

Regular Ball Super Ball

Create a class Ball.

Ball objects should accept one argument for "ball type" when instantiated.

If no arguments are given, ball objects should instantiate with a "ball type" of "regular."

using System;

public class Ball {
public string ballType { get; set; }
public Ball(){
ballType = "regular";
}
public Ball(string ballType) {
this.ballType=ballType;
}
}

其他人的解法:

一:使用了Optional Arguments ,这是C#4.0的新特性。

What's New in Visual C# 2010

using System;

public class Ball {
public string ballType { get; set; } public Ball(string ballType = "regular") {
this.ballType = ballType;
}
}

关于构造函数中使用this ,可以参考这个https://msdn.microsoft.com/zh-cn/library/ms173115(v=vs.110).aspx

using System;

public class Ball {
public string ballType { get; set; } public Ball(string ballType) {
this.ballType = ballType;
} public Ball(): this("regular"){}
}

A constructor can invoke another constructor in the same object by using the this keyword. Like base, this can be used with or without parameters, and any parameters in the constructor are available as parameters tothis, or as part of an expression. For example, the second constructor in the previous example can be rewritten using this:

public Employee(int weeklySalary, int numberOfWeeks)
: this(weeklySalary * numberOfWeeks)
{
}

The use of the this keyword in the previous example causes this constructor to be called:

public Employee(int annualSalary)
{
salary = annualSalary;
}

Regular Ball Super Ball的更多相关文章

  1. HDU 5821 Ball (排序)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5821 有n个盒子,每个盒子最多装一个球. 现在进行m次操作,每次操作可以将l到r之间盒子的球任意交换. ...

  2. HDU 5821 Ball (贪心)

    Ball 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5821 Description ZZX has a sequence of boxes nu ...

  3. NOI.ac模拟赛20181021 ball sequence color

    T1 ball 可以发现每次推动球时,是将每个球的位置 −1-1−1 ,然后把最左边的球放到 P−1P-1P−1 处. 记个 −1-1−1 次数,再用set维护就好了. #include <bi ...

  4. java面试题及答案(转载)

    JAVA相关基础知识1.面向对象的特征有哪些方面 1.抽象:抽象就是忽略一个主题中与当前目标无关的那些方面,以便更充分地注意与当前目标有关的方面.抽象并不打算了解全部问题,而只是选择其中的一部分,暂时 ...

  5. Android Animation学习(四) ApiDemos解析:多属性动画

    Android Animation学习(四) ApiDemos解析:多属性动画 如果想同时改变多个属性,根据前面所学的,比较显而易见的一种思路是构造多个对象Animator , ( Animator可 ...

  6. Android Animation学习(三) ApiDemos解析:XML动画文件的使用

    Android Animation学习(三) ApiDemos解析:XML动画文件的使用 可以用XML文件来定义Animation. 文件必须有一个唯一的根节点: <set>, <o ...

  7. 关于初级java面试问题的一些整理 (部分转自他人)

    1.面向对象的特征有哪些方面       1.抽象: 抽象就是忽略一个主题中与当前目标无关的那些方面,以便更充分地注意与当前目标有关的方面.抽象并不打算了解全部问题,而只是选择其中的一部分,暂时不用部 ...

  8. 转载:Java面试笔试题大汇总

    本文来源于:http://blog.csdn.net/wulianghuan 1.面向对象的特征有哪些方面 1).抽象: 抽象就是忽略一个主题中与当前目标无关的那些方面,以便更充分地注意与当前目标有关 ...

  9. Java面试题大全(四)

    JAVA代码查错 1. abstract class Name { private String name; public abstract boolean isStupidName(String n ...

随机推荐

  1. input onfocus onblur

    <input type="text" style="color:#999" value="账户" onfocus='if(this.v ...

  2. ubuntu server版连接vpn服务器

    命令行的方法: 1.要下载pptp的客户端    sudo apt-get install pptp-linux 2.创建连接     sudo pptpsetup –create vpn001 –s ...

  3. uniquery 在win2008 下hold的问题。

    TmpQry.ReadOnly := True; 加上这句解决,原因未知!

  4. sirius的python学习笔记(1)

    1.可以通过try...except语句来简单的判断字符串是否为整数值,如例程 x = raw_input('>') try: print int(x) except ValueError: r ...

  5. 浅谈String类型

    首先,我们要知道的是String类型是一个引用类型,它的基类是Object.并且它的内容是只读的. 我们有时候经常会看到两个字符串类型,一个是“Sting”,一个是“string”.大写的String ...

  6. linux set,env和export

    set,env和export这三个命令都可以用来显示shell变量 set 显示当前shell的变量,包括当前用户的变量 env 显示当前用户的变量 export 显示当前导出成用户变量的shell变 ...

  7. fragment第二次载入就报错

    1.布局中加入一个<fragment 标签,第一次载入的时候是正常的,第二次加载的时候,就直接crashed,退出 2.查到原因Caused by: java.lang.IllegalArgum ...

  8. 360随身wifi怎样购买?360随身wifi怎样预约?

    ---恢复内容开始--- 360随身wifi怎样购买 想要购买360随身Wifi,可以登录360随身Wifi的官网wifi.360.cn,或者直接登陆京东商城进行购买,售价为19.9元,分黑.白两色. ...

  9. 1509 -- Glass Beads POJ

    题意:求一个字符串的最小表示的开始下标 就当模板题写了 把字符串重复一遍,再建后缀自动机,贪心的选最小字典序在上面走len步 因为走出来的一定是子串,长度又是len,所以一定是原来的字符串旋转得到的, ...

  10. ASP.NET MVC 数据分页思想及解决方案代码

    作为一个程序猿,数据分页是每个人都会遇到的问题.解决方案更是琳琅满目,花样百出.但基本的思想都是差不多的. 下面给大家分享一个简单的分页器,让初学者了解一下最简单的分页思想,以及在ASP.NET MV ...