楼主: Lisrelchen
927 2

C# Essentials [推广有奖]

  • 0关注
  • 62粉丝

VIP

已卖:4194份资源

院士

67%

还不是VIP/贵宾

-

TA的文库  其他...

Bayesian NewOccidental

Spatial Data Analysis

东西方数据挖掘

威望
0
论坛币
50288 个
通用积分
83.6306
学术水平
253 点
热心指数
300 点
信用等级
208 点
经验
41518 点
帖子
3256
精华
14
在线时间
766 小时
注册时间
2006-5-4
最后登录
2022-11-6

楼主
Lisrelchen 发表于 2016-5-22 01:05:42 |AI写论文
1论坛币

  1. C# Essentials, 2nd Edition
  2. By: Ben Albahari; Peter Drayton; Brad Merrill
  3. Publisher: O'Reilly Media, Inc.
  4. Pub. Date: January 25, 2002
  5. Print ISBN-13: 978-0-596-00315-9
  6. Pages in Print Edition: 218
  7. Subscriber Rating: 0 out of 5 rating [0 Ratings]
复制代码

本帖隐藏的内容

C# Essentials, 2nd Edition.rar (477.55 KB, 需要: 5 个论坛币) 本附件包括:
  • C# Essentials, 2nd Edition.pdf






关键词:Essentials Essential Essen ESS TIA rating Peter Media

沙发
Lisrelchen(未真实交易用户) 发表于 2016-5-22 01:06:34
  1. Example: Building and Using Types
  2. In this program, we build our own type called Counter and another type called Test that uses instances of the Counter. The Counter type uses the predefined type int, and the Test type uses the static function member WriteLine of the Console class defined in the System namespace:
  3. // Imports types from System namespace, such as Console
  4. using System;
  5. class Counter { // New types are typically classes or structs
  6.   // --- Data members ---
  7.   int value; // field of type int
  8.   int scaleFactor; // field of type int

  9.   // Constructor, used to initialize a type instance
  10.   public Counter(int scaleFactor) {
  11.     this.scaleFactor = scaleFactor;  
  12.   }
  13.   // Method
  14.   public void Inc(  ) {
  15.     value+=scaleFactor;
  16.   }
  17.   // Property
  18.   public int Count {
  19.     get {return value; }
  20.   }
  21. }
  22. class Test {
  23.   // Execution begins here
  24.   static void Main(  ) {

  25.     // Create an instance of counter type
  26.     Counter c = new Counter(5);
  27.     c.Inc(  );
  28.     c.Inc(  );
  29.     Console.WriteLine(c.Count); // prints "10";

  30.     // Create another instance of counter type
  31.     Counter d = new Counter(7);
  32.     d.Inc(  );
  33.     Console.WriteLine(d.Count); // prints "7";
  34.    }
  35. }
复制代码

藤椅
Lisrelchen(未真实交易用户) 发表于 2016-5-22 01:09:11
  1. Definite Assignment
  2. Variables in C# (except in unsafe contexts) must be assigned a value before they are used. A variable is either explicitly assigned a value or automatically assigned a default value. Automatic assignment occurs for static fields, class instance fields, and array elements not explicitly assigned a value. For example:
  3. using System;
  4. class Test {
  5.   int v;
  6.   // Constructors that initialize an instance of a Test
  7.   public Test(  ) {} // v will be automatically assigned to 0
  8.   public Test(int a) { // explicitly assign v a value
  9.      v = a;
  10.   }
  11.   static void Main(  ) {
  12.     Test[] iarr = new Test [2]; // declare array
  13.     Console.WriteLine(iarr[1]); // ok, elements assigned to null
  14.     Test t;
  15.     Console.WriteLine(t); // error, t not assigned
  16.   }
  17. }
复制代码

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-27 00:41