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 ...
随机推荐
- [WinForm]为TextBox设置水印文字
关键代码: using System; using System.Runtime.InteropServices; using System.Windows.Forms; namespace WinF ...
- C#,PHP对应加密函数
require_once "JunDes.php"; $jDes=new JunDes(); echo $jDes->encode('98765'); //echo $jDe ...
- C#使用Zxing2.0生成二维码 带简单中心LOGO
参考:http://www.open-open.com/lib/view/open1379214678162.html 代码:http://files.cnblogs.com/halo/%E4%BA% ...
- wamp Server2.5 配置 自定义目录
煎熬了两天终于找到了方法!!! 前提先改成中文 右键"W"图表-> Language -> chinese; 成功改为中文. 自定义目录步骤: 一.添加一个Alias ...
- aix用命令查监听端口对应的进程
--aix$netstat -an|grep LISTEN|grep 7867tcp4 0 0 *.7867 *.* LISTEN$netstat -Aan|grep 7867f1000e00029f ...
- Delphi Base64 编解码函数
Delphi 自带 Base64 编解码的单元, EncdDecd这个单元提供两套四个公开函数: 对流的编解码:procedure EncodeStream(Input, Output: TStrea ...
- 拥抱ARM妹子 序章!ARM妹子~~ 哥我来啦!
一个负心汉即将移情别恋,从51转到ARM妹子啦?其实8是的,俺准备开后宫.哇——咔~咔~~.考虑功耗和成本等问题,只有51肯定是不够的,所以嘛~~(一脸坏笑)嘿嘿~~,ARM妹子俺追定了.出于对ARM ...
- Code for the Homework1 改进
#include <iostream> #include <vector> #include "shape.h" //using namespace std ...
- ExtJs 4.2.1 复选框数据项动态加载(更新一下)
最近在做博客项目,后台管理用的是ExtJs4.2.1版本,因为是初学所以在使用的时候也遇到不少的这样或那样的问题,也写了不少这方面的博客,今天要写的博客是关于复选框数据项动态的加载功能,以前也没用过, ...
- 图片流滚动效果html代码(复制)
<!doctype html> <html> <head> <meta charset="utf-8" /> < ...