输出整型数据
using System
;
using System
.Collections
.Generic
;
using System
.Linq
;
using System
.Text
;
using System
.Threading
.Tasks
;
namespace Integer
{
class Program
{
static void Main(string[] args
)
{
sbyte Sbyte
= 100;
byte Byte
= 200;
char Char
= '\u0061';
short Short
= 30000;
ushort UShort
= 60000;
int Int
= 200000000;
uint Uint
= 40000000;
long Long
= 9000000000000;
ulong ULong
= 18000000000000;
Console
.WriteLine("有符号字节型\t{0}", Sbyte
);
Console
.WriteLine("无符号字节型\t{0}", Byte
);
Console
.WriteLine("字符型\t\t{0}", Char
);
Console
.WriteLine("有符号短整型\t{0}",Short
) ;
Console
.WriteLine("无符号短整型\t{0}",UShort
);
Console
.WriteLine("有符号整型\t{0}",Int
);
Console
.WriteLine("无符号整型\t{0}", Uint
);
Console
.WriteLine("有符号长整型\t{0}", Long
);
Console
.WriteLine("无符号长整型\t{0}", ULong
);
Console
.ReadKey();
}
}
}
判断矩形是否为正方形——结构体和布尔型
using System
;
using System
.Collections
.Generic
;
using System
.Linq
;
using System
.Text
;
using System
.Threading
.Tasks
;
namespace Integer
{
class Rectangle
{
struct rectangle
{
public int width
;
public int height
;
public bool IsSquare()
{
return width
== height
;
}
}
static void Main(string[]args
)
{
rectangle re
= new rectangle();
re
.width
= 100;
re
.height
= 200;
Console
.WriteLine("矩形的宽是:{0};矩形的长是:{1}。", re
.width
, re
.height
);
bool result
=re
.IsSquare();
Console
.WriteLine("矩形{0}正方形", result
);
Console
.ReadKey();
}
}
}
Enum
using System
;
using System
.Collections
.Generic
;
using System
.Linq
;
using System
.Text
;
using System
.Threading
.Tasks
;
namespace Integer
{
class Enum
{
enum Animal
: byte
{
Dog
=0,
Cat
=1,
Mouse
=2
}
static void Main(string []args
)
{
Animal animal
= Animal
.Cat
;
switch (animal
)
{
case Animal
.Dog
:
Console
.WriteLine("狗");
break;
case Animal
.Cat
:
Console
.WriteLine("猫");
break;
case Animal
.Mouse
:
Console
.WriteLine("鼠");
break;
default:
break;
}
Console
.ReadKey();
}
}
}
修改圆柱体的高度和底面半径——引用类型
using System
;
using System
.Collections
.Generic
;
using System
.Linq
;
using System
.Text
;
using System
.Threading
.Tasks
;
namespace Integer
{
class Reference
{
struct Column
{
public Circle Circle
;
public int Height
;
}
class Circle
{
public int Radius
;
}
static void Main(string []args
)
{
Column column1
= new Column();
Circle circle1
= new Circle();
column1
.Height
= 20;
column1
.Circle
= circle1
;
circle1
.Radius
= 10;
Console
.WriteLine("圆柱体1高度:{0}", column1
.Height
);
Console
.WriteLine("圆柱体1底面半径:{0}",column1
.Circle
.Radius
);
Console
.WriteLine("将圆柱体1赋值给圆柱体2");
Column column2
= column1
;
Console
.WriteLine("将圆形1半径改为30");
circle1
.Radius
= 30;
Console
.WriteLine("圆柱体1的底面半径:{0}", column1
.Circle
.Radius
);
Console
.WriteLine("圆柱体2的底面半径:{0}", column2
.Circle
.Radius
);
Console
.WriteLine("圆柱体1的高度:{0}", column1
.Height
);
Console
.WriteLine("圆柱体2的高度:{0}", column2
.Height
);
Console
.WriteLine("将圆柱体2的高度改为40");
column2
.Height
= 40;
Console
.WriteLine("圆柱体1的高度:{0}", column1
.Height
);
Console
.WriteLine("圆柱体2的高度:{0}", column2
.Height
);
Console
.ReadKey();
}
}
}
转载请注明原文地址:https://ipadbbs.8miu.com/read-58727.html