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 ...
随机推荐
- js获取url参数值的两种方式
js获取url参数值的方法有很多,下面也为大家介绍两种. 方法一:正则分析法 function getQueryString(name) { var reg = new RegExp(" ...
- php header函数要点
发布:snowfly 来源:网络 [大 中 小] 相信很多人写程序时,使用 header(location) 进行跳转往往不记得写 exit() 语句,这种做法存在严重风险. 从浏览器来看 ...
- ECshop sina
http://blog.sina.com.cn/s/blog_5327408801019ofa.html http://blog.sina.com.cn/u/2624360105 http://blo ...
- Dapper.ColumnMapper 的使用
using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; usin ...
- 数据可视化(一)-Matplotlib简易入门
本节的内容来源:https://www.dataquest.io/mission/10/plotting-basics 本节的数据来源:https://archive.ics.uci.edu/ml/d ...
- 怎样在自己的网站上做自动生成当前url的二维码
$todoString="www.maomii.com"; generateQRfromGoogle($todoString); /** * google api 最多4296个字 ...
- The 50 Most Essential Pieces of Classical Music
1. Die Zauberflöte ("The Magic Flute"), K. 620: Overture London Philharmonic Orchestra 7:2 ...
- 编译andriod源码出错:java.lang.UnsupportedClassVersionError: com/google/doclava/Doclava : Unsupported
问题:java.lang.UnsupportedClassVersionError: com/google/doclava/Doclava : Unsupported update-java-alte ...
- 关于FileSystemWatcher监听文件创建
FileSystemWatcher中的Created事件不但可以监听用户创建的文件,当用户删除某个文件时,系统会在再监听的那个盘上的回收站创建一个文件,在回收站创建的文件也会触发Created事件,而 ...
- 【BZOJ 1053】[HAOI2007]反素数ant
Description 对于任何正整数x,其约数的个数记作g(x).例如g(1)=1.g(6)=4.如果某个正整数x满足:g(x)>g(i) 0<i<x,则称x为反质数.例如,整数1 ...