首页 > 开发 > 综合 > 正文

Beginner with c# 4

2024-07-21 02:20:01
字体:
来源:转载
供稿:网友

1¡£4 ô¤¶¨òåààðí£¨predefined types£©

c#ìṩáëò»ïµáðô¤¶¨òåààðí¡£ëüãçóëc/c++óð²»éùïàëæµäµø·½¡£ô¤¶¨òåòýóãààðíóðobjectºístring¡£
objectààðíêçëùóðæäëûààðíµä»ù´¡¡£

ô¤¶¨òåààðí°ü਷ûºåêý¡¢îþ·ûºåêý¡¢¸¡µã¡¢²¼¶û¡¢×ö·ûºíꮽøöæêý¡£·ûºåêýóð£ºsbyte¡¢short¡¢
intºílong£»îþ·ûºåêýóð£ºbyte¡¢ushort¡¢uintºíulong£»¸¡µãêýóð£ºfloatºídouble¡£

²¼¶ûààðí¾íïñò»¸ö¿ª¹ø£¬ö»óðá½öö״쬣ºtrue»òfalse¡£c#¶ô²¼¶ûµäòªçó±èc/c++ñï¸ñ£¬óëjavaààëæ¡£
ôúc#öðfalse²»µèóú0£¬trueò²²»µèóú1£»falseºítrue¶¼êçµ¥¶à·öàë³öà´µäò»¸ööµ¡£ñ§¹ýc/c++µäíøóñ
¶¼öªµà£º*/
int i = 0;
if (i = 0) { // bug: ó¦¸ãêç (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();
}
}
/*
õâò»½úóðµã³áãæ¡££º£¨
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表