Regular Ball Super Ball
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的新特性。
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的更多相关文章
- HDU 5821 Ball (排序)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5821 有n个盒子,每个盒子最多装一个球. 现在进行m次操作,每次操作可以将l到r之间盒子的球任意交换. ...
- HDU 5821 Ball (贪心)
Ball 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5821 Description ZZX has a sequence of boxes nu ...
- NOI.ac模拟赛20181021 ball sequence color
T1 ball 可以发现每次推动球时,是将每个球的位置 −1-1−1 ,然后把最左边的球放到 P−1P-1P−1 处. 记个 −1-1−1 次数,再用set维护就好了. #include <bi ...
- java面试题及答案(转载)
JAVA相关基础知识1.面向对象的特征有哪些方面 1.抽象:抽象就是忽略一个主题中与当前目标无关的那些方面,以便更充分地注意与当前目标有关的方面.抽象并不打算了解全部问题,而只是选择其中的一部分,暂时 ...
- Android Animation学习(四) ApiDemos解析:多属性动画
Android Animation学习(四) ApiDemos解析:多属性动画 如果想同时改变多个属性,根据前面所学的,比较显而易见的一种思路是构造多个对象Animator , ( Animator可 ...
- Android Animation学习(三) ApiDemos解析:XML动画文件的使用
Android Animation学习(三) ApiDemos解析:XML动画文件的使用 可以用XML文件来定义Animation. 文件必须有一个唯一的根节点: <set>, <o ...
- 关于初级java面试问题的一些整理 (部分转自他人)
1.面向对象的特征有哪些方面 1.抽象: 抽象就是忽略一个主题中与当前目标无关的那些方面,以便更充分地注意与当前目标有关的方面.抽象并不打算了解全部问题,而只是选择其中的一部分,暂时不用部 ...
- 转载:Java面试笔试题大汇总
本文来源于:http://blog.csdn.net/wulianghuan 1.面向对象的特征有哪些方面 1).抽象: 抽象就是忽略一个主题中与当前目标无关的那些方面,以便更充分地注意与当前目标有关 ...
- Java面试题大全(四)
JAVA代码查错 1. abstract class Name { private String name; public abstract boolean isStupidName(String n ...
随机推荐
- [DevExpress]设置RepositoryItemComboBox只可下拉选择不可编辑
将TextEditStyle属性设置如下即可: 希望有所帮助!
- Sublime Text 3 入门(插件控制台安装)
下载地址:http://www.sublimetext.com/3 以windows 32位系统为例 直接点击Windows下载: Package Control插件控制台(有这个才可以安装插件) h ...
- PHP 跨域写cookie
实际工作中,类似这样的要求很多,比如说,我们有两个域名,我们想实现在一个域名登录后,能自动完成另一个域名的登录,也就是PASSPORT的功能. 我只写一个大概,为了测试的方便,先编辑hosts文件,加 ...
- Python变量类型(l整型,长整形,浮点型,复数,列表,元组,字典)学习
#coding=utf-8 __author__ = 'Administrator' #Python变量类型 #Python数字,python支持四种不同的数据类型 int整型 long长整型 flo ...
- Android中获取应用程序(包)的大小-----PackageManager的使用(二)
通过第一部分<<Android中获取应用程序(包)的信息-----PackageManager的使用(一)>>的介绍,对PackageManager以及 AndroidMani ...
- 【通信】Netty JBOSS提供的一个java开源框架
Netty是由JBOSS提供的一个java开源框架.Netty提供异步的.事件驱动的网络应用程序框架和工具,用以快速开发高性能.高可靠性的网络服务器和客户端程序dsf. 也就是说,Netty 是一个基 ...
- [Objective-C]关联(objc_setAssociatedObject、objc_getAssociatedObject、objc_removeAssociatedObjects)(转)
转载自:http://blog.csdn.net/onlyou930/article/details/9299169 分类: Objective-C2013-07-11 11:54 3420人阅读 评 ...
- Duilib介绍以及各个类的简介
转自http://note.sdo.com/u/icez/n/mvO-X~jyVnpFnM01A0000m DirectUI意为直接在父窗口上绘图(Paint on parent dc directl ...
- 现代浏览器原生js获取id号方法
<div id="tests" class="a b c" style="color:#f00">123</div> ...
- [转载]线程间操作无效: 从不是创建控件“ListBox1”的线程访问它
解决方法有两种: 1.Control.CheckForIllegalCrossThreadCalls = false 2.用委托解决线程安全问题