基本数据类型操作
2012-09-14 00:00
253 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
namespace Ex03._04
{
class Program
{
static void Main(string[] args)
{
objectFunctionality();
dataTypeFunctionality();
charFunctionality();
parseFromString();
userDatesAndTimes();
userBigInteger();
Console.ReadKey();
}
static void objectFunctionality()
{
Console.WriteLine("类型继承测试:");
Int32 intValue = 12;
Console.WriteLine("{0}.GetHashCode()={1}", intValue, intValue.GetHashCode());
Console.WriteLine("{0}.Equals(23)={1}", intValue, intValue.Equals(23));
Console.WriteLine("{0}.ToString()={1}", intValue, intValue.ToString());
Console.WriteLine("{0}.GetType()={1}", intValue, intValue.GetType());
Console.WriteLine("{0}.GetTypeCode()={1}", intValue, intValue.GetTypeCode());
Console.WriteLine();
Console.Beep();
}
static void dataTypeFunctionality()
{
Console.WriteLine("数据类型展示:");
Console.WriteLine("Max of Int32:{0}", Int32.MaxValue);
Console.WriteLine("Min of Int32:{0}", Int32.MinValue);
Console.WriteLine("Max of Double:{0}", Double.MaxValue);
Console.WriteLine("Min of Double:{0}", Double.MinValue);
Console.WriteLine("Double.PositiveInfinity:{0}", Double.PositiveInfinity);
Console.WriteLine("Double.NegativeInfinity:{0}", Double.NegativeInfinity);
Console.WriteLine("Boolean.FalseString()={0}", Boolean.FalseString);
Console.WriteLine("Boolean.TrueString()={0}", Boolean.TrueString);
Console.WriteLine();
Console.Beep();
}
static void charFunctionality()
{
Console.WriteLine("Char类型功能展示:");
Char myChar = 'a';
Console.WriteLine("Char.IsDigit('{0}'):{1}", myChar, Char.IsDigit(myChar));
Console.WriteLine("Char.IsLetter('{0}'):{1}", myChar, Char.IsLetter(myChar));
Console.WriteLine("Char.IsLetterOrDigit('{0}'):{1}", myChar, Char.IsLetterOrDigit(myChar));
Console.WriteLine("Char.IsWhiteSpace('Hello World!',5):{0}", Char.IsWhiteSpace("Hello World!", 5));
Console.WriteLine("Char.IsWhiteSpace('Hello World!',6):{0}", Char.IsWhiteSpace("Hello World!", 6));
Console.WriteLine("Char.IsPunctuation('?'):{0}", Char.IsPunctuation('?'));
Console.WriteLine();
Console.Beep();
}
static void parseFromString()
{
Console.WriteLine("从字符串解析数据:");
Boolean b = Boolean.Parse("True");
Console.WriteLine("Value of b:{0}", b);
Double d = Double.Parse("99.98");
Console.WriteLine("Value of d:{0}", d);
Int32 i = Int32.Parse("63");
Console.WriteLine("Value of i:{0}", i);
Char c = Char.Parse("w");
Console.WriteLine("Value of c:{0}", c);
Console.WriteLine();
Console.Beep();
}
static void userDatesAndTimes()
{
Console.WriteLine("使用System.DateTime和System.TimeSpan");
//构造日期,年月日
DateTime dt = new DateTime(2012, 9, 14);
Console.WriteLine("这是{0}月的第{1}天", dt.Month, dt.Day);
Console.WriteLine("目前的日期:{0}", dt.ToShortDateString());
//增加2个月
dt = dt.AddMonths(4);
Console.WriteLine("增加2个月之后的日期:{0}", dt.ToShortDateString());
Console.WriteLine("目前是夏令时吗?:{0}", dt.IsDaylightSavingTime());
//构造时间,时分秒
TimeSpan ts = new TimeSpan(13, 25, 0);
Console.WriteLine(ts);
//减去15分钟
Console.WriteLine("减去15分钟:{0}", ts.Subtract(new TimeSpan(0, 15, 0)));
Console.Beep();
Console.WriteLine();
}
static void userBigInteger()
{
Console.WriteLine("使用大数BigInteger:");
BigInteger biggy = BigInteger.Parse("999999999999999999999999999999999999999999999999999999999");
Console.WriteLine("这是一个大数吗?{0}", biggy);
//是不是偶数
Console.WriteLine("Is this an even value?{0}", biggy.IsEven);
//是2的幂吗
Console.WriteLine("Is this a power of two?{0}", biggy.IsPowerOfTwo);
BigInteger reallyBig = BigInteger.Multiply(biggy, BigInteger.Parse("8888888888888888888888888888888888"));
Console.WriteLine("这可是个够大的数:{0}", reallyBig);
Console.Beep();
Console.WriteLine();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
namespace Ex03._04
{
class Program
{
static void Main(string[] args)
{
objectFunctionality();
dataTypeFunctionality();
charFunctionality();
parseFromString();
userDatesAndTimes();
userBigInteger();
Console.ReadKey();
}
static void objectFunctionality()
{
Console.WriteLine("类型继承测试:");
Int32 intValue = 12;
Console.WriteLine("{0}.GetHashCode()={1}", intValue, intValue.GetHashCode());
Console.WriteLine("{0}.Equals(23)={1}", intValue, intValue.Equals(23));
Console.WriteLine("{0}.ToString()={1}", intValue, intValue.ToString());
Console.WriteLine("{0}.GetType()={1}", intValue, intValue.GetType());
Console.WriteLine("{0}.GetTypeCode()={1}", intValue, intValue.GetTypeCode());
Console.WriteLine();
Console.Beep();
}
static void dataTypeFunctionality()
{
Console.WriteLine("数据类型展示:");
Console.WriteLine("Max of Int32:{0}", Int32.MaxValue);
Console.WriteLine("Min of Int32:{0}", Int32.MinValue);
Console.WriteLine("Max of Double:{0}", Double.MaxValue);
Console.WriteLine("Min of Double:{0}", Double.MinValue);
Console.WriteLine("Double.PositiveInfinity:{0}", Double.PositiveInfinity);
Console.WriteLine("Double.NegativeInfinity:{0}", Double.NegativeInfinity);
Console.WriteLine("Boolean.FalseString()={0}", Boolean.FalseString);
Console.WriteLine("Boolean.TrueString()={0}", Boolean.TrueString);
Console.WriteLine();
Console.Beep();
}
static void charFunctionality()
{
Console.WriteLine("Char类型功能展示:");
Char myChar = 'a';
Console.WriteLine("Char.IsDigit('{0}'):{1}", myChar, Char.IsDigit(myChar));
Console.WriteLine("Char.IsLetter('{0}'):{1}", myChar, Char.IsLetter(myChar));
Console.WriteLine("Char.IsLetterOrDigit('{0}'):{1}", myChar, Char.IsLetterOrDigit(myChar));
Console.WriteLine("Char.IsWhiteSpace('Hello World!',5):{0}", Char.IsWhiteSpace("Hello World!", 5));
Console.WriteLine("Char.IsWhiteSpace('Hello World!',6):{0}", Char.IsWhiteSpace("Hello World!", 6));
Console.WriteLine("Char.IsPunctuation('?'):{0}", Char.IsPunctuation('?'));
Console.WriteLine();
Console.Beep();
}
static void parseFromString()
{
Console.WriteLine("从字符串解析数据:");
Boolean b = Boolean.Parse("True");
Console.WriteLine("Value of b:{0}", b);
Double d = Double.Parse("99.98");
Console.WriteLine("Value of d:{0}", d);
Int32 i = Int32.Parse("63");
Console.WriteLine("Value of i:{0}", i);
Char c = Char.Parse("w");
Console.WriteLine("Value of c:{0}", c);
Console.WriteLine();
Console.Beep();
}
static void userDatesAndTimes()
{
Console.WriteLine("使用System.DateTime和System.TimeSpan");
//构造日期,年月日
DateTime dt = new DateTime(2012, 9, 14);
Console.WriteLine("这是{0}月的第{1}天", dt.Month, dt.Day);
Console.WriteLine("目前的日期:{0}", dt.ToShortDateString());
//增加2个月
dt = dt.AddMonths(4);
Console.WriteLine("增加2个月之后的日期:{0}", dt.ToShortDateString());
Console.WriteLine("目前是夏令时吗?:{0}", dt.IsDaylightSavingTime());
//构造时间,时分秒
TimeSpan ts = new TimeSpan(13, 25, 0);
Console.WriteLine(ts);
//减去15分钟
Console.WriteLine("减去15分钟:{0}", ts.Subtract(new TimeSpan(0, 15, 0)));
Console.Beep();
Console.WriteLine();
}
static void userBigInteger()
{
Console.WriteLine("使用大数BigInteger:");
BigInteger biggy = BigInteger.Parse("999999999999999999999999999999999999999999999999999999999");
Console.WriteLine("这是一个大数吗?{0}", biggy);
//是不是偶数
Console.WriteLine("Is this an even value?{0}", biggy.IsEven);
//是2的幂吗
Console.WriteLine("Is this a power of two?{0}", biggy.IsPowerOfTwo);
BigInteger reallyBig = BigInteger.Multiply(biggy, BigInteger.Parse("8888888888888888888888888888888888"));
Console.WriteLine("这可是个够大的数:{0}", reallyBig);
Console.Beep();
Console.WriteLine();
}
}
}
相关文章推荐
- djangoORM数据类型及基本操作
- IO流 操作基本类型数据的流对象 DataStream
- IO流(操作基本数据类型的流对象DataStream)
- MySQL---数据类型和表的基本操作
- 基本数据类型,文件操作
- Java基础知识强化之IO流笔记57:数据输入输出流(操作基本数据类型)
- 第2章_基本数据类型和基本操作_编程练习Exercise2.7通过创建窗口进行大小写的切换
- IO流(操作基本数据类型的流)
- scala学习-基本数据类型和简单操作5
- redis的基本数据类型及基本操作(一)
- C++ STL 有关于SET集合的基本操作,本文不包含涉及到自定义数据类型的排序
- 第一节:Halcon基本的数据类型及其操作
- IO流 DataInputStream和DataOutputStream 用于操作基本数据类型
- JAVA学习笔记(2)基本数据类型和基本操作
- Java的IO操作(二) - 带缓冲区的流对象、写入基本数据类型、实现命令行中的copy命令
- JAVA基础再回首(二十三)——操作基本数据类型的流、内存操作流、打印流、随机访问流、合并流、序列化流
- 操作基本数据类型的流对象DataStream
- 黑马程序员-学习日志-操作基本数据类型的数据流
- 操作基本数据类型,字节数组的流 和 字符编码
- redis 基本数据类型及操作学习(二)