Beginner with c# 4 (轉)
Beginner with c# 4 (轉)[@more@]1¡£4 Ô¤¶¨ÒåÀàÐÍ£¨Predefined types£©
ÌṩÁËһϵÁÐÔ¤¶¨ÒåÀàÐÍ¡£ËüÃÇÓëc/c++Óв»ÉÙÏàËƵĵط½¡£Ô¤¶¨ÒåÒýÓÃÀàÐÍÓкÍstring¡£
objectÀàÐÍÊÇËùÓÐÆäËûÀàÐ͵Ļù´¡¡£
Ô¤¶¨ÒåÀàÐÍ°üÀ¨·ûºÅÊý¡¢ÎÞ·ûºÅÊý¡¢¸¡µã¡¢²¼¶û¡¢×Ö·ûºÍÊ®½øÖÆÊý¡£·ûºÅÊýÓУºsbyte¡¢short¡¢
intºÍlong£»ÎÞ·ûºÅÊýÓУºbyte¡¢ushort¡¢uintºÍulong£»¸¡µãÊýÓУºfloatºÍdouble¡£
²¼¶ûÀàÐ;ÍÏñÒ»¸ö¿ª¹Ø£¬Ö»ÓÐÁ½ÖÖ״̬£ºtrue»òfalse¡£c#¶Ô²¼¶ûµÄÒªÇó±Èc/c++Ñϸñ£¬ÓëÀàËÆ¡£
ÔÚc#ÖÐfalse²»µÈÓÚ0£¬trueÒ²²»µÈÓÚ1£»falseºÍtrue¶¼Êǵ¥¶À·ÖÀë³öÀ´µÄÒ»¸öÖµ¡£Ñ§¹ýc/c++µÄÍøÓÑ
¶¼ÖªµÀ£º*/
int i = 0;
if (i = 0) { // : Ó¦¸ÃÊÇ (i == 0)
....
}
/* ÊÇûÓÐÎÊÌâµÄ¡£µ«ÔÚc#ÖлáÒý·¢Ò»¸ö±àÒë´íÎó£¨error CS0029: Cannot implicitly convert
type 'int' to 'bool'£©¡£µ±È»£¬ÕâÑùÎþÉüÁËÒ»µãûÓбØÒªµÄÁé»îÐÔ¡£ÎÒÃÇÔÙÒ²²»ÄÜÕâÑù£º*/
string str;
....
if(str = Console.ReadLine()) {
Console.WriteLine("Your comments are: {0}",str);
....
/* ¶ø±ØÐ룺*/
using System;
class BoolTest
{
static void Main() {
string str = Console.ReadLine();//Ò²¿ÉÒÔ£ºstring str;
if(str == "") // if((str = Console.ReadLine()) == "")
Console.WriteLine("i can't read your comments. Please tell me something! O.K.?");
else
Console.WriteLine("Your comments are: {0}",str);
}
}
/*
ÎÒ³ÁËÒ»ÕÅÔ¤¶¨ÒåÀàÐ͵ļò±í¹©´ó¼Ò²Î¿¼¡£
Type Description Examples
object The ultimate base type of all other types object o = new Stack();
string String type; a string is a sequence of string s = "Hello";
Unicode characters
sbyte 8-bit signed integral type sbyte val = 12;
short 16-bit signed integral type short val = 12;
int 32-bit signed integral type int val = 12;
long 64-bit signed integral type long val1 = 12;
long val2 = 34L;
byte 8-bit unsigned integral type byte val1 = 12;
byte val2 = 34U;
ushort 16-bit unsigned integral type ushort val1 = 12;
ushort val2 = 34U;
uint 32-bit unsigned integral type uint val1 = 12;
uint val2 = 34U;
ulong 64-bit unsigned integral type ulong val1 = 12;
ulong val2 = 34U;
ulong val3 = 56L;
ulong val4 = 78UL;
float Single-precision floating point type float value = 1.23F;
double Double-precision floating point type double val1 = 1.23
double val2 = 4.56D;
bool Boolean type; a bool value is either bool value = true;
true or false
char Character type; a char value is a Unicode char value = 'h';
character
decimal Precise decimal type with 28 significant digits decimal value = 1.23M;
ÄãÒ²¿ÉÒÔ×Ô¶¨Òå×Ô¼ºµÄÔ¤¶¨ÒåÀàÐÍ£¬¿ÉÒÔÕâÑù£º*/
using System;
struct Digit
{...}
class Test
{
static void TestInt() {
int a = 1;
int b = 2;
int c = a + b;
Console.WriteLine(c);
}
static void TestDigit() {
Digit a = (Digit) 1;
Digit b = (Digit) 2;
Digit c = a + b;
Console.WriteLine(c);
}
static void Main() {
TestInt();
TestDigit();
}
}
/*
ÕâÒ»½ÚÓеã³ÁÃÆ¡££º£¨
ÌṩÁËһϵÁÐÔ¤¶¨ÒåÀàÐÍ¡£ËüÃÇÓëc/c++Óв»ÉÙÏàËƵĵط½¡£Ô¤¶¨ÒåÒýÓÃÀàÐÍÓкÍstring¡£
objectÀàÐÍÊÇËùÓÐÆäËûÀàÐ͵Ļù´¡¡£
Ô¤¶¨ÒåÀàÐÍ°üÀ¨·ûºÅÊý¡¢ÎÞ·ûºÅÊý¡¢¸¡µã¡¢²¼¶û¡¢×Ö·ûºÍÊ®½øÖÆÊý¡£·ûºÅÊýÓУºsbyte¡¢short¡¢
intºÍlong£»ÎÞ·ûºÅÊýÓУºbyte¡¢ushort¡¢uintºÍulong£»¸¡µãÊýÓУºfloatºÍdouble¡£
²¼¶ûÀàÐ;ÍÏñÒ»¸ö¿ª¹Ø£¬Ö»ÓÐÁ½ÖÖ״̬£ºtrue»òfalse¡£c#¶Ô²¼¶ûµÄÒªÇó±Èc/c++Ñϸñ£¬ÓëÀàËÆ¡£
ÔÚc#ÖÐfalse²»µÈÓÚ0£¬trueÒ²²»µÈÓÚ1£»falseºÍtrue¶¼Êǵ¥¶À·ÖÀë³öÀ´µÄÒ»¸öÖµ¡£Ñ§¹ýc/c++µÄÍøÓÑ
¶¼ÖªµÀ£º*/
int i = 0;
if (i = 0) { // : Ó¦¸ÃÊÇ (i == 0)
....
}
/* ÊÇûÓÐÎÊÌâµÄ¡£µ«ÔÚc#ÖлáÒý·¢Ò»¸ö±àÒë´íÎó£¨error CS0029: Cannot implicitly convert
type 'int' to 'bool'£©¡£µ±È»£¬ÕâÑùÎþÉüÁËÒ»µãûÓбØÒªµÄÁé»îÐÔ¡£ÎÒÃÇÔÙÒ²²»ÄÜÕâÑù£º*/
string str;
....
if(str = Console.ReadLine()) {
Console.WriteLine("Your comments are: {0}",str);
....
/* ¶ø±ØÐ룺*/
using System;
class BoolTest
{
static void Main() {
string str = Console.ReadLine();//Ò²¿ÉÒÔ£ºstring str;
if(str == "") // if((str = Console.ReadLine()) == "")
Console.WriteLine("i can't read your comments. Please tell me something! O.K.?");
else
Console.WriteLine("Your comments are: {0}",str);
}
}
/*
ÎÒ³ÁËÒ»ÕÅÔ¤¶¨ÒåÀàÐ͵ļò±í¹©´ó¼Ò²Î¿¼¡£
Type Description Examples
object The ultimate base type of all other types object o = new Stack();
string String type; a string is a sequence of string s = "Hello";
Unicode characters
sbyte 8-bit signed integral type sbyte val = 12;
short 16-bit signed integral type short val = 12;
int 32-bit signed integral type int val = 12;
long 64-bit signed integral type long val1 = 12;
long val2 = 34L;
byte 8-bit unsigned integral type byte val1 = 12;
byte val2 = 34U;
ushort 16-bit unsigned integral type ushort val1 = 12;
ushort val2 = 34U;
uint 32-bit unsigned integral type uint val1 = 12;
uint val2 = 34U;
ulong 64-bit unsigned integral type ulong val1 = 12;
ulong val2 = 34U;
ulong val3 = 56L;
ulong val4 = 78UL;
float Single-precision floating point type float value = 1.23F;
double Double-precision floating point type double val1 = 1.23
double val2 = 4.56D;
bool Boolean type; a bool value is either bool value = true;
true or false
char Character type; a char value is a Unicode char value = 'h';
character
decimal Precise decimal type with 28 significant digits decimal value = 1.23M;
ÄãÒ²¿ÉÒÔ×Ô¶¨Òå×Ô¼ºµÄÔ¤¶¨ÒåÀàÐÍ£¬¿ÉÒÔÕâÑù£º*/
using System;
struct Digit
{...}
class Test
{
static void TestInt() {
int a = 1;
int b = 2;
int c = a + b;
Console.WriteLine(c);
}
static void TestDigit() {
Digit a = (Digit) 1;
Digit b = (Digit) 2;
Digit c = a + b;
Console.WriteLine(c);
}
static void Main() {
TestInt();
TestDigit();
}
}
/*
ÕâÒ»½ÚÓеã³ÁÃÆ¡££º£¨
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752043/viewspace-987288/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Beginner with C# (轉)C#
- Beginner with c# 5 (轉)C#
- Beginner with c# 6 (轉)C#
- Beginner with c# 2 (轉)C#
- Beginner with c# 3 (轉)C#
- Beginner with c# 7 (轉)C#
- VB程式設計師眼中的C# 4 (轉)程式設計師C#
- C#字串轉換為數字的4種方法C#字串
- C#學習4C#
- QT beginner QFileDialogQT
- WHAT IS C# (轉)C#
- C#學習日記4C#
- C#:Dictionary轉DataTableC#
- 可怕的 C# (轉)C#
- C#聊天程式 (轉)C#
- C# 和 API (轉)C#API
- C#問答 (轉)C#
- c# DataTable轉ListC#
- C# 操作xml(轉)C#XML
- AtCoder Beginner Contest 360
- AtCoder Beginner Contest 343
- AtCoder Beginner Contest 344
- AtCoder Beginner Contest 345
- AtCoder Beginner Contest 346
- atcoder beginner 346 題解
- 【AtCoder Beginner Contest 347】
- AtCoder Beginner Contest 348
- AtCoder Beginner Contest 347
- AtCoder Beginner Contest 349
- AtCoder Beginner Contest 363
- AtCoder Beginner Contest 364
- AtCoder Beginner Contest 365
- AtCoder Beginner Contest 361
- AtCoder Beginner Contest 361)
- AtCoder Beginner Contest 362
- AtCoder Beginner Contest 366
- AtCoder Beginner Contest 369
- AtCoder Beginner Contest 044