ImageVerifierCode 换一换
你正在下载:

Quick C#.docx

[预览]
格式:DOCX , 页数:30 ,大小:24.67KB ,
资源ID:25152461      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/25152461.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Quick C#.docx)为本站会员(b****9)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

Quick C#.docx

1、Quick C#Quick C#Learn C# in less than an hour. Discover the C# language constructs and features in a brief yet comprehensive way using code examples. This article is especially good if you know C+ and feel lazy about learning C#!IntroductionC# is a language with the features of C+, programming style

2、 like Java and rapid application model of BASIC. If you already know the C+ language, it will take you less than an hour to quickly go through the syntax of C#. Familiarity with Java will be a plus, as Java program structure, the concept of packages and garbage collection will definitely help you le

3、arn C# more quickly. So while discussing C# language constructs, I will assume, you know C+.This article discusses the C# language constructs and features using code examples, in a brief and comprehensive way, so that you just by having a glance at the code, can understand the concepts.Note: This ar

4、ticle is not for C# gurus. There must be some other beginners articles on C#, but this is yet another one.Following topics of C# language are discussed: Program structure Namespaces Data types Variables Operators and expressions Enumerations Statements Classes and structs Modifiers Properties Interf

5、aces Function parameters Arrays Indexers Boxing and unboxing Delegates Inheritance and polymorphismFollowing are not discussed: Things which are common in C+ and C#. Concepts like garbage collection, threading, file processing etc. Data type conversions Exception handling .NET libraryProgram structu

6、reLike C+, C# is case-sensitive. Semi colon (;) is the statement separator. Unlike C+, there are no separate declaration (header) and implementation (CPP) files in C#. All code (class declaration and implementation) is placed in one file with extensioncs.Have a look at this Hello world program in C#

7、.using System;namespace MyNameSpaceclass HelloWorld static void Main(string args) Console.WriteLine (Hello World); Everything in C# is packed into a class and classes in C# are packed into namespaces (just like files in a folder). Like C+, a main method is the entry point of your program. C+s main f

8、unction is calledmainwhereas C#s main function starts with capital M and is named asMain.No need to put a semi colon after a class block orstructdefinition. It was in C+, C# doesnt require that.NamespaceEvery class is packaged into a namespace. Namespaces are exactly the same concept as in C+, but i

9、n C# we use namespaces more frequently than in C+. You can access a class in a namespace using dot (.) qualifier.MyNameSpaceis the namespace in hello world program above.Now consider you want to access theHelloWorldclass from some other class in some other namespace.using System;namespace AnotherNam

10、eSpace class AnotherClass public void Func() Console.WriteLine (Hello World); Now from yourHelloWorldclass you can access it as:using System;using AnotherNameSpace; / you will add this using statementnamespace MyNameSpaceclass HelloWorld static void Main(string args) AnotherClass obj = new AnotherCl

11、ass(); obj.Func(); In .NET library,Systemis the top level namespace in which other namespaces exist. By default there exists a global namespace, so a class defined outside a namespace goes directly into this global namespace and hence you can access this class without any qualifier.You can also defi

12、ne nested namespaces.UsingThe#includedirective is replaced withusingkeyword, which is followed by a namespace name. Just asusingSystemas above.Systemis the base level namespace in which all other namespaces and classes are packed. The base class for all objects isObjectin theSystemnamespace.Variable

13、sVariables in C# are almost the same as in C+ except for these differences: Variables in C# (unlike C+), always need to be initialized before you access them, otherwise you will get compile time error. Hence, its impossible to access an un-initialized variable. You cant access a “dangling” pointer i

14、n C#. An expression that indexes an array beyond its bounds is also not accessible. There areno global variablesor functions in C# and the behavior of globals is achieved through static functions and static variables.Data typesAll types of C# are derived from a base classobject. There are two types

15、of data types: Basic/ built-in types User-defined typesFollowing is a table which lists built-in C# types:TypeBytesDescriptionbyte1unsigned bytesbyte1signed byteshort2signed shortushort2unsigned shortint4signed integeruint4unsigned integerlong8signed longulong8unsigned longfloat4floating point numbe

16、rdouble8double precision numberdecimal8fixed precision numberstringUnicode stringcharUnicode charbooltrue,falsebooleanNote: Type range in C# and C+ are different, example, long in C+ is 4 bytes, and in C# it is 8 bytes. Also theboolandstringtypes are different than those in C+.boolaccepts onlytruean

17、dfalseand not any integer.User defined types includes: Classes Structs InterfacesMemory allocation of the data types divides them into two types: Value types Reference typesValue typesValues types are those data types which are allocated in stack. They include: All basic or built-in types exceptstri

18、ngs Structs EnumtypesReference typesReference types are allocated on heap and are garbage collected when they are no longer being used. They are created usingnewoperator, and there is nodeleteoperator for these types unlike C+ where user has to explicitly delete the types created usingdeleteoperator

19、. In C#, they are automatically collected by garbage collector.Reference types include: Classes Interfaces Collection types likeArrays StringEnumerationEnumerations in C# are exactly like C+. Defined through a keywordenum.Example:enum Weekdays Saturday, Sunday, Monday, Tuesday, Wednesday, Thursday,

20、FridayClasses and structsClasses andstructs are same as in C+, except the difference of their memory allocation. Objects of classes are allocated in heap, and are created usingnew, where asstructs are allocated in stack.Structs in C# are very light and fast data types. For heavy data types, you shou

21、ld create classes.Examples:struct Date int day; int month; int year; class Date int day; int month; int year; string weekday; string monthName; public int GetDay() return day; public int GetMonth() return month; public int GetYear() return year; public void SetDay(int Day) day = Day ; public void Se

22、tMonth(int Month) month = Month; public void SetYear(int Year) year = Year; public bool IsLeapYear() return (year/4 = 0); public void SetDate (int day, int month, int year) .PropertiesIf you are familiar with the object oriented way of C+, you must have an idea of properties. Properties in above exa

23、mple ofDateclass areday,monthandyearfor which in C+, you writeGetandSetmethods. C# provides a more convenient, simple and straight forward way of accessing properties.So above class can be written as:using System;class Date public int Day get return day; set day = value; int day; public int Month ge

24、t return month; set month = value; int month; public int Year get return year; set year = value; int year; public bool IsLeapYear(int year) return year%4= 0 ? true: false; public void SetDate (int day, int month, int year) this.day = day; this.month = month; this.year = year; Here is the way you wil

25、l get and set these properties:class User public static void Main() Date date = new Date(); date.Day = 27; date.Month = 6; date.Year = 2003; Console.WriteLine (Date: 0/1/2, date.Day, date.Month, date.Year); ModifiersYou must be aware ofpublic,privateandprotectedmodifiers that are commonly used in C+

26、. I will here discuss some new modifiers introduced by C#.readonlyreadonlymodifier is used only for the class data members. As the name indicates, thereadonlydata members can only be read, once they are written either by directly initializing them or assigning values to them in constructor. The diff

27、erence between thereadonlyandconstdata members is thatconstrequires you to initialize with the declaration, that is directly. See example code:class MyClass const int constInt = 100; /directly readonly int myInt = 5; /directly readonly int myInt2; public MyClass() myInt2 = 8; /Indirectly public Func

28、() myInt = 7; /Illegal Console.WriteLine(myInt2.ToString(); sealedsealedmodifier with a class dont let you derive any class from it. So you use thissealedkeyword for the classes which you dont want to be inherited from.sealed class CanNotbeTheParent int a = 5;unsafeYou can define an unsafe context i

29、n C# usingunsafemodifier. In unsafe context, you can write an unsafe code, example: C+ pointers etc. See the following code:public unsafe MyFunction( int * pInt, double* pDouble) int* pAnotherInt = new int; *pAnotherInt = 10; pInt = pAnotherInt; . *pDouble = 8.9; InterfacesIf you have an idea of COM

30、, you will immediately know what I am talking about. Aninterfaceis the abstract base class containing only the function signatures whose implementation is provided by the child class. In C#, you define such classes as interfaces using theinterfacekeyword. .NET is based on such interfaces. In C#, where you cant use multiple class inheritance, whi

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1