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 ...
随机推荐
- spring-cloud-turbine
turbine主要用于聚合hystrix的监控数据 依赖pom <dependencyManagement> <dependencies> <dependency> ...
- HTML5 + SOCKET视频传输
<html> <head> <meta http-equiv="content-type" content="text/html; char ...
- 淘宝IP地址库采集器c#代码
这篇文章主要介绍了淘宝IP地址库采集器c#代码,有需要的朋友可以参考一下. 最近做一个项目,功能类似于CNZZ站长统计功能,要求显示Ip所在的省份市区/提供商等信息.网上的Ip纯真数据库,下载下来一看 ...
- php取整的几种方法
php取整的几种方式. floor 舍去法取整 语法格式:float floor ( float value )返回不大于value 的下一个整数,将value 的小数部分舍去取整.floor() 返 ...
- KM3
本科:读完一本书,知道book里讲的是什么,带有知识吸收: 硕士:读完一本书,知道book里的内容,而且还能发现相关的问题,带有知识的思考: 博士:读完一本书,知道book里的内容,而且还能发现相关的 ...
- IEEE 754 浮点数的四种舍入方式
四种舍入方向: 向最接近的可表示的值:当有两个最接近的可表示的值时首选"偶数"值:向负无穷大(向下):向正无穷大(向上)以及向0(截断). 说明:默认模式是最近舍入(Round t ...
- ACM俱乐部 字符串
数制转换分数: 2 时间限制:1 秒 内存限制:32 兆 特殊判题: 否 提交:59 解决: 24 标签 进制转换 题目描述 求任意两个不同进制非负整数的转换(2进制-16进制),所给整数在long所 ...
- linux -- 启动时启动服务或者执行命令
运行等级 首先,我们需要知道Linux系统关于运行等级的知识.在不同的linux系统上(例如ubuntu和Fedora)这些数字与和所代表的意义可能不同,但主要的有以下几个: 单用户模式. 多用户模式 ...
- C# 将datatable 转换json
public static string DataTableToJson(DataTable dt) { StringBuilder jsonBuilder = new StringBuilder() ...
- 阿里云Ubuntu服务器安装java环境
一.下载jdk wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-secureb ...