• 軟件測試技術
  • 軟件測試博客
  • 軟件測試視頻
  • 開源軟件測試技術
  • 軟件測試論壇
  • 軟件測試沙龍
  • 軟件測試資料下載
  • 軟件測試雜志
  • 軟件測試人才招聘
    暫時沒有公告

字號: | 推薦給好友 上一篇 | 下一篇

Beginner with c# 4

發布: 2007-6-30 23:38 | 作者: admin | 來源: | 查看: 10074次 | 進入軟件測試論壇討論

領測軟件測試網 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();
}
}
/*
ÕâÒ»½ÚÓеã³ÁÃÆ¡££º£¨

延伸閱讀

文章來源于領測軟件測試網 http://www.anti-gravitydesign.com/


關于領測軟件測試網 | 領測軟件測試網合作伙伴 | 廣告服務 | 投稿指南 | 聯系我們 | 網站地圖 | 友情鏈接
版權所有(C) 2003-2010 TestAge(領測軟件測試網)|領測國際科技(北京)有限公司|軟件測試工程師培訓網 All Rights Reserved
北京市海淀區中關村南大街9號北京理工科技大廈1402室 京ICP備10010545號-5
技術支持和業務聯系:info@testage.com.cn 電話:010-51297073

軟件測試 | 領測國際ISTQBISTQB官網TMMiTMMi認證國際軟件測試工程師認證領測軟件測試網

国产97人人超碰caoprom_尤物国产在线一区手机播放_精品国产一区二区三_色天使久久综合给合久久97