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. C# Winform程序打包

    1.新建一个安装项目,起名“Setup3” 2.点击应用程序文件夹 3.在右侧右键点击添加文件 注意:是Debug文件夹下所有程序 接着在添加你的应用程序项目的时候,多添加一个msiexec.exe进 ...

  2. MongoDB的安全性

    上篇文章介绍Mongo启动了,一般数据库启动,下面的操作就是登录数据库了,之前测试数据库是否正常安装的时候也登录过数据库,现在回想一下,好像连用户名和密码都没有输入,找几篇帖子来探究下Mongodb的 ...

  3. 如何实现zs无限期试用

    要删除的文件有两个,分别是.zs与10_0..zs保存的是版本号,10_0保存的是注册码,这两个文件存在的原理是:zend studio 每次启动的会检查这两个文件的创建时间,和当前日期对比,超过30 ...

  4. Django文档——Model字段类型(Field Types)

    大部分内容参考自http://wrongwaycn.github.io/django11/topics/db/models/index.html#topics-db-models ,内容是django ...

  5. Speech Patterns (string)

    People often have a preference among synonyms of the same word. For example, some may prefer "t ...

  6. Android “NetworkOnMainThreadException”出错原因及解决办法

    原因: 不允许在主线程中通讯 方法1:非要在主线程中,当然也可以,这样去处理: StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Build ...

  7. 使用NPIO操作Excel

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using NPOI.SS. ...

  8. 【Spring-boot多数据库】Spring-boot JDBC with multiple DataSources sample

    application.properties spring.ds_items.driverClassName=org.postgresql.Driver spring.ds_items.url=jdb ...

  9. 解决.net定时器在iis7上不执行问题

    今天第一次在博客园发帖,以前一直在潜水,在这里也是学了不少东西.感谢各位园友 废话不多说,这也是我工作中遇到的问题: protected void Application_Start(object s ...

  10. EXTJS 3.0 资料 控件之 itemselector 用法

    var dsform = new Ext.data.ArrayStore({ data: [[123, 'One Hundred Twenty Three'], ['1', '今天星期一'], ['2 ...