Beginner with c# 4

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

时间: 2024-09-24 03:22:45

Beginner with c# 4的相关文章

新手教程之:循环网络和LSTM指南 (A Beginner’s Guide to Recurrent Networks and LSTMs)

  新手教程之:循环网络和LSTM指南 (A Beginner's Guide to Recurrent Networks and LSTMs)   本文翻译自:http://deeplearning4j.org/lstm.html   其他相关教程: 1. 深度神经网络简介 http://deeplearning4j.org/zh-neuralnet-overview 2. 卷积网络 http://deeplearning4j.org/zh-convolutionalnets   目录: 1.

(转)A Beginner's Guide To Understanding Convolutional Neural Networks Part 2

Adit Deshpande CS Undergrad at UCLA ('19) Blog About A Beginner's Guide To Understanding Convolutional Neural Networks Part 2 Introduction Link to Part 1                 In this post, we'll go into a lot more of the specifics of ConvNets. Disclaimer:

Beginner: Using Servlets to display, insert and update records in database.(1)

servlet Displaying Records from the Database with Java Servlets. Overview : In this article I'll explain each step you need to know to display records from the database using Servlets. The steps for displaying records in JSP pages and Java Beans are

Beginner: Using Servlets to display, insert and update records in database.(3)

servlet Updating records in the Database with Java Servlets. Overview : This article is next in the series of articles about selecting, inserting, updating and deleting records from the database using JDBC. In this article we will learn how to update

Beginner: Using Servlets to display, insert and update records in database.(2)

servlet Inserting records into the Database with Java Servlets. Overview : This article is next in the series of articles about selecting, inserting, updating and deleting records from the database using JDBC. In this article we will learn how to ins

Beginner with c# 5

1.5 数组类型(Array types) 数组可以是一维的,也可是多维的.数祖的成员可以是整齐的,也可以是变长(jagged)的. 一维的数组是最普通,最简单的.这里值给出一个例子,就不多解释了.*/ using System; class Test { static void Main() { int[] arr = new int[5]; for (int i = 0; i < arr.Length; i++) arr[i] = i * i; for (int i = 0; i < ar

Beginner with c# 7

1.7 语句(Statements) c#借用了c/c++大多数的语句方法,不过仍然有些值得注意的地方.还有些地方是有所改动的. 在这里,我只提一些c#特有的东东. 1.7.10 "foreach"语句 "foreach"语句列举一个集合内的所有元素,并对这些元素执行一系列的操作.还是看看例子吧:*/ using System; using System.Collections; class Test { static void WriteList(ArrayLis

Beginner with C#

1 绪论 c# 是一种简练,时髦(?),面向对象(object oriented),类型可靠(type-safe)的 编程语言.它(发音:C sharp)是从c/c++发展而来的(?俺觉得更象是java),和c/c++ 是一个语系.所以,很容易被c/c++的程序员接受.c#的目标是结合Visual Basic的高产和 C++质朴的力量. c#将会是vs7的一分子.vs7还支持vb,vc和标记语言--VBScript和JScript.所有这些语言 都会在Next Generation Window

Beginner with c# 2

1.2 自动化的内存管理(Automatic memory management) 手动管理内存需要程序员自行分配和释放内存块.这要求程序员有清晰的头脑和对整个运行过程有十分的 把握(好难!).而c#把程序员从这难以承担的任务中解放出来.在多数的情况下,这种自动内存管理提 高代码的质量和程序员的生产力.并且,不会对程序的意图和执行产生幅面的影响(?俺可不相信m$的鬼 话).不过,估计比java的回收站好一点吧.因为c#出道迟嘛(尽胡扯).好了,来看看例子.*/ using System; pub