Description:

Hey Codewarrior!

You already implemented a Cube class, but now we need your help again! I'm talking about constructors. We don't have one. Let's code two: One taking an integer and one handling no given arguments!

Also we got a problem with negative values. Correct the code so negative values will be switched to positive ones!

The constructor taking no arguments should assign 0 to Cube's Side property.

http://www.codewars.com/kata/playing-with-cubes-ii/csharp

using System;

public class Cube
{
private int Side; //This cube needs your help.
//Define a constructor which takes one integer and assignes its value to 'Side'
public Cube()
{} public Cube(int side)
{
this.Side = Math.Abs(side);
} public int GetSide()
{
return this.Side;
} public void SetSide(int s)
{
this.Side = Math.Abs(s);
}
}

可以使用this来处理构造函数,无参构造函数,字段的默认值,可以通过调用有参函数来处理

赋值的时候,可以调用类本身的函数

public class Cube
{
private int Side; //This cube needs your help.
//Define a constructor which takes one integer and assignes its value to 'Side'
public Cube(int s)
{
SetSide(s);
} public Cube()
: this()
{ }
public int GetSide()
{
return Side;
} public void SetSide(int s)
{
Side = System.Math.Abs(s);
}
}

可以使用函数的缺省参数

using System;

public class Cube
{
private Int32 _side; public Cube(Int32 Side = ){
SetSide(Side);
} public Int32 GetSide()
{
return this._side;
} public void SetSide(Int32 Side)
{
this._side = Math.Abs(Side);
}
}

Playing with cubes II的更多相关文章

  1. Codeforces Round #274 (Div. 2) B. Towers

    As you know, all the kids in Berland love playing with cubes. Little Petya has n towers consisting o ...

  2. Codeforces 479B. Towers 暴力

    纯暴力..... B. Towers time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  3. Playing with ptrace, Part II

    Playing with ptrace, Part II Issue From Issue # December Dec , By Pradeep Padala inSysAdmin In Part ...

  4. [LeetCode] Guess Number Higher or Lower II 猜数字大小之二

    We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to gues ...

  5. (转) Deep Reinforcement Learning: Playing a Racing Game

    Byte Tank Posts Archive Deep Reinforcement Learning: Playing a Racing Game OCT 6TH, 2016 Agent playi ...

  6. Codeforces Round #184 (Div. 2) E. Playing with String(博弈)

    题目大意 两个人轮流在一个字符串上删掉一个字符,没有字符可删的人输掉游戏 删字符的规则如下: 1. 每次从一个字符串中选取一个字符,它是一个长度至少为 3 的奇回文串的中心 2. 删掉该字符,同时,他 ...

  7. HDU 4043 FXTZ II (组合数学-排列组合)

    FXTZ II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Su ...

  8. Flip Game I && II

    Flip Game I Problem Description: You are playing the following Flip Game with your friend: Given a s ...

  9. hdu 5265 pog loves szh II

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5265 pog loves szh II Description Pog and Szh are pla ...

随机推荐

  1. Unity学习笔记(3):获取对象

    在上一篇文章中(Unity映射注册)中概要介绍了Unity中的映射机制,本节主要介绍对象获取,包括默认获取,通过名称获取,获取全部对象,同时通过加载配置文件,然后再获取对象. 通过代码获取对象 方式1 ...

  2. javascript 事件的学习

    1.事件绑定: addEventListener , removeEventListener.是dom2级别的事件绑定 attachEvent , detachEvent 是IE的事件绑定. 2. 事 ...

  3. Node.js之【正则表达式函数之match、test、exec、search、split、replace使用详解】

    1. Match函数 使用指定的正则表达式函数对字符串惊醒查找,并以数组形式返回符合要求的字符串 原型:stringObj.match(regExp) 参数: stringObj 必选项,需要去进行匹 ...

  4. Demo学习: Collapsible Panels

    Collapsible Panels 设置TUniPanel布局属性,布局属性在Ext里是比较常用的属性,当前版本虽已经提供了布局功能,但很不完善,比如当Panel.TitlePosition=tpR ...

  5. ISO-9126 软件质量模型

    摘要 在软件开发过程中,软件的质量是一个重要的因素,而软件体系结构在整个过程中显得尤为重要.软件的质量需求是在开发初期的非功能性需求,对软件的体系结构影响很大.但是并不意味着一味的追求质量,必须在效率 ...

  6. Spark Streaming揭秘 Day29 深入理解Spark2.x中的Structured Streaming

    Spark Streaming揭秘 Day29 深入理解Spark2.x中的Structured Streaming 在Spark2.x中,Spark Streaming获得了比较全面的升级,称为St ...

  7. Django文档——Model字段选项(Field Options)

    建立一个简易Model class Person(models.Model): GENDER_CHOICES=( (1,'Male'), (2,'Female'), ) name=models.Cha ...

  8. Django Admin后台使用tinymc 富文本编辑器

    1.CDN地址 <script src="//cdn.tinymce.com/4/tinymce.min.js"></script> 2.修改base.ht ...

  9. HDFS知识体系 思维导图

  10. IOS平台汉字转拼音方案

    iOS/Mac OS X 汉字转拼音 网络流行的汉字转拼音方案是带一个拼音码表,速度快.其实Core Foundation也提供了一种方案,而且还带声调! NSMutableString *ms =  ...