程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> Beginner with c# 4

Beginner with c# 4

編輯:關於C語言
1&IExcl;£4 Ô¤¶¨ÒåÀàÐÍ£¨Predefined types£©

c#ÌṩÁËһϵÁÐÔ¤¶¨ÒåÀàÐÍ&IExcl;£ËüÃÇÓëc/c++Óв»ÉÙÏàËƵĵط½¡£Ô¤¶¨ÒåÒýÓÃÀàÐÍÓÐobjectºÍstring&IExcl;£
objectÀàÐÍÊÇËùÓÐÆäËûÀàÐ͵Ļù´¡&IExcl;£

Ô¤¶¨ÒåÀàÐÍ°üÀ¨·ûºÅÊý¡¢ÎÞ·ûºÅÊý¡¢¸¡µã¡¢²¼¶û&IExcl;¢×Ö·ûºÍÊ®½øÖÆÊý¡£·ûºÅÊýÓУºsbyte¡¢short&IExcl;¢
intºÍlong£»ÎÞ·ûºÅÊýÓУºbyte¡¢ushort¡¢uintºÍulong£»¸¡µãÊýÓУºfloatºÍdouble&IExcl;£

²¼¶ûÀàÐ;ÍÏñÒ»¸ö¿ª¹Ø£¬Ö»ÓÐÁ½ÖÖ״̬£ºtrue»òfalse&IExcl;£c#¶Ô²¼¶ûµÄÒªÇó±Èc/c++Ñϸñ£¬Ó&eUML;JavaÀàËÆ&IExcl;£
ÔÚc#ÖÐfalse²»µÈÓÚ0£¬trueÒ²²»µÈÓÚ1£»falseºÍtrue¶¼Êǵ¥¶À·ÖÀë³öÀ´µÄÒ»¸öÖµ&IExcl;£Ñ§¹ýc/c++µÄÍøÓÑ
¶¼ÖªµÀ£º*/
int i = 0;
if (i = 0) { // Bug: Ó¦¸ÃÊÇ (i == 0)
....
}
/* ÊÇûÓÐÎÊÌâµÄ&IExcl;£µ«ÔÚc#ÖлáÒý·¢Ò»¸ö±àÒ&eUML;´íÎó£¨error CS0029: Cannot implicitly convert
type 'int' to 'bool'£©¡£µ±È»£¬ÕâÑùÎþÉüÁËÒ»µãûÓбØÒªµÄÁé»îÐÔ&IExcl;£ÎÒÃÇÔÙÒ²²»ÄÜÕâÑù£º*/
string str;
....
if(str = Console.ReadLine()) {
Console.WriteLine("Your comments are: {0}",str);
....
/* ¶ø±ØÐ&eUML;£º*/
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);
}
}
/*
ÎÒ³­ÁËÒ»ÕÅÔ¤¶¨ÒåÀàÐ͵ļò±í¹©´ó¼Ò²Î¿¼&IExcl;£

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();
}
}
/*
ÕâÒ»½ÚÓеã³ÁÃÆ&IExcl;££º£¨
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved