Playing with cubes II
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的更多相关文章
- 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 ...
- Codeforces 479B. Towers 暴力
纯暴力..... B. Towers time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Playing with ptrace, Part II
Playing with ptrace, Part II Issue From Issue # December Dec , By Pradeep Padala inSysAdmin In Part ...
- [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 ...
- (转) Deep Reinforcement Learning: Playing a Racing Game
Byte Tank Posts Archive Deep Reinforcement Learning: Playing a Racing Game OCT 6TH, 2016 Agent playi ...
- Codeforces Round #184 (Div. 2) E. Playing with String(博弈)
题目大意 两个人轮流在一个字符串上删掉一个字符,没有字符可删的人输掉游戏 删字符的规则如下: 1. 每次从一个字符串中选取一个字符,它是一个长度至少为 3 的奇回文串的中心 2. 删掉该字符,同时,他 ...
- HDU 4043 FXTZ II (组合数学-排列组合)
FXTZ II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...
- Flip Game I && II
Flip Game I Problem Description: You are playing the following Flip Game with your friend: Given a s ...
- 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 ...
随机推荐
- php header头信息 举例
发布:sunday01 来源:Net [大 中 小] 转自:http://www.jbxue.com/article/6915.html 用于演示PHP header()函数用法的代码,介 ...
- CentOS配置vsftpd遇到550错误的解决办法
默认情况下用root是无法连接的,你可以创建一个非root帐户登录,但是登录是可以登录,却没有办法创建或是上传文件.有人说,可以把 SELinux关掉,可是这样未免也有点尺度太大了,其实是SELinu ...
- 国产CPU研究单位及现状
1.国产CPU主要研制单位 (1)高性能通用CPU(“大CPU”,主要应用于高性能计算及服务器等) 主要研发单位:中国科学院计算所.北大众志.国防科技大学.上海高性能集成电路设计中心 (2)安全适用计 ...
- CentOS7下源码安装mysql5.6
目录 准备工作 运行环境 确认你的安装版本 下载mysql 安装mysql 准备安装环境 编译和安装 配置mysql 单实例配置 单实例配置方法 添加防火墙 ...
- 奖学金评分系统(系统分析与设计版与Delphi实现代码)
一.系统规划 1.1 项目背景介绍 在奖学金评比过程中,学生综合测评是学校普遍采用的评比手段.对学生实施综合素质测评的目的在于正确评价学生的综合素质,为评奖学金提供依据,实现学生教育管理工作的标准化. ...
- Device eth0 does not seem to be present
解决办法: 首先,打开/etc/udev/rules.d/70-persistent-net.rules内容如下面例子所示: # vi /etc/udev/rules.d/70-persistent- ...
- sysfs接口整理
SYS节点 目录结构: 1:sysfs相关知识点介绍(介绍sysfs的体系结构) 2:sys节点核心知识(使用sys节点核心的知识) 3:代码实例(创建sys节点的代码实例) 1:sysfs相关知识点 ...
- php生成xml的四种方法(转)
<?xml version="1.0" encoding="utf-8"?> <article> <item> <ti ...
- Android Studio 单刷《第一行代码》系列 06 —— Fragment 生命周期
前情提要(Previously) 本系列将使用 Android Studio 将<第一行代码>(书中讲解案例使用Eclipse)刷一遍,旨在为想入坑 Android 开发,并选择 Andr ...
- C#学习笔记(二)
1.注释:注销,解释2.单行://多行:/**/文档注释:///按enter主食要保证 别人一看就明白3.快速对期待吗:ctrl+k+d,按住ctrl不放,按k,迅速抬起,再按d(按D得时候k已经抬起 ...