Sunday, October 24, 2010

"CLR Via C #" Study Notes (3) constant and field



"CLR Via C #" book read twice before the rough, but has failed to understand in depth, but a lot of content is forgotten, is now ready to re-read it, and read the written part, because the process of writing is also a deeper understanding of the process. Study of this series be considered a record, it would not be easy after their inspection, if you still some help, I am very happy. I am a selective look at the book, so order and may not be the same as the order book.

CLR Via C # Study Notes (1) primitive type value type reference type

CLR Via C # Study Notes (2) boxing and unboxing

CLR Via C # Study Notes (3) constant and the field (cosnt readonly)

Constants and fields are the type of data members, but the difference is significant. See below under the constant example to understand

1. Constant value will never change. There are many types of fields, the value of non-read-only field can be changed.

2. Constant value must be determined at compile time, that the definition would assign. Compiled constant values on the preservation of the assembly metadata; field is stored in dynamic memory at run time to get field values.

3. Constant definition must be primitive types, the primitive types can refer to (CLR Via C # Study Notes (1) primitive type value type reference type); field definitions can be any type.

4. Because the constant value can not change, it can be seen as a static type, in the IL code, you can see there is constant static modifier, so call time and call the static field, as the class name directly. Constant names ; field before the call to the static fields and constants, like the class name directly. field name, call the non-static field must be an instance of the class. ,

5. C # does not allow modification of constant use of static, because the constant implied in itself is static type; field can use the static, use the static definition of the field is static fields.

1 Create a class library project named Oec2003ClassLibrary, in default of the class to write the following code in Class1

1 namespace Oec2003ClassLibrary

2 (

3 public class Class1

4 (

5 public const double PI = 3.14;

6

7 public static double _pi = 3.14;

8)

9)

10

2 Create a web project, add a reference to the Oec2003ClassLibrary class library project, the new page ConstTest.aspx, write the following code in the PageLoad

1 protected void Page_Load (object sender, EventArgs e)

2 (

3 Response.Write (Class1.PI + "

");

4 Response.Write (Class1._pi);

5)

3 will ConstTest Make start page, run, you can see the result as follows

4 will now Oec2003ClassLibrary project Class1's code to read as follows, and then re-compile the project.

1 namespace Oec2003ClassLibrary

2 (

3 public class Class1

4 (

5 public const double PI = 3.1415926;

6

7 public static double _pi = 3.1415926;

8)

9)

5, just refresh the page, you can see the following results

Page 6 of the new run ConstTest the following results can be seen

As can be seen from the above example, the application does not re-compile the case, the constant value will never change. If the application program wants to get a new constant value, Jiu must be re-compiled, so when an application program running set of applications that want to get another value of concentration, Ze Bu Neng use the constant, Ke Yi using the read-only Ziduan (readonly).

Field is also a type of data members, field modifiers are static readonly volatile, there is no modification of the Modified field is an instance of ordinary fields. static readonly can be used together, is a static read-only field. The volatile in the later part of the introduction.

About readonly must pay attention to

l 1 when the readonly field is modified by the value type, when the call to change the field if the value of view, it will compile error.

l 2 when the readonly field is modified with reference types, the call can not change its reference, but you can change the application object's value, see the following example.

1 projects in Oec2003ClassLibrary Class1.cs file to write the following code

1 namespace Oec2003ClassLibrary

2 (

3 public class Class1

4 (

5 public const double PI = 3.14;

6 public static readonly double _pi = 3.14;

7

8 public static readonly User user = new User ("oec2003");

9)

10 public class User

11 (

12 public User (string name)

13 (

14 Name = name;

15)

16 public string Name (get; set;)

17)

18)

19

2 In the web project, add pages, is named Readonly.aspx, PageLoad code below

1 protected void Page_Load (object sender, EventArgs e)

2 (

3 User user = Class1.user;

4 Class1.user.Name = "oec2005"; / / static read-only field is applied correctly modify the value of the object, run in the page display oec2005

5

6 Class1.user = new User ("oec2005"); / / error can not compile, can not change to another reference

7

8 Response.Write (user.Name);

9)

10

From the above you can know about the read-only (Readonly) field, once defined can not change its value, even if a reference type can only change the reference value of the object. However, it also is not as absolute, the following came to see how to use reflection to achieve change in the value of read-only field.

1 As used in reflection, the first reference to the namespace using System.Reflection;, and then modify the code in Class1.

1 namespace Oec2003ClassLibrary

2 (

3 public class Class1

4 (

5 public readonly Int32 _age = 25;

6 public readonly User _user = new User ("oec2003");

7)

8 public class User

9 (

10 public User (string name)

11 (

12 Name = name;

13)

14 public string Name (get; set;)

15)

16)

2 modified PageLoad code, will use reflection before the contents of the output read-only field.

1 protected void Page_Load (object sender, EventArgs e)

2 (

3 Class1 myClass = new Class1 ();

4

5 User user = myClass._user;

6

7 Response.Write ("Name:" + user.Name + "Age:" + myClass._age);

8)

The results are as follows

3 modified PageLoad code, using reflection and then modify the value of the output read-only field.

1 protected void Page_Load (object sender, EventArgs e)

2 (

3 Class1 myClass = new Class1 ();

4

5 Type myType = typeof (Oec2003ClassLibrary.Class1);

6 myType.GetField ("_age"). SetValue (myClass, 30); / / change the value type the value of read-only field

7 myType.GetField ("_user"). SetValue (myClass, new User ("glass")); / / change the reference value of read-only field

8

9 User user = myClass._user;

10 Response.Write ("Name:" + user.Name + "Age:" + myClass._age);

11)

The results are as follows

Oh, we can see whether it is read-only field value type or reference type read-only field can be successfully modified by reflection.

In some interviews often encounter the difference between const and readonly This problem of the root base is the difference between constant and fields, readonly field is modified by a field only, the practical application of the selection according to const or readonly actual demand, const better performance, because there is no allocation of memory, but many restrictions, such as restrictions on the type definition, seems not very flexible.







Recommended links:



Stop ekrn exe problems quick fixing tip



Hot Covert Surveillance



3G market to look FORWARD to



CTI Capital coveted



Picked Audio Recorders



ASF To MPG



The world's major MEDIA on the views of Chrome OS



Evaluate Java And JavaScript



Hot Graphic Viewers



MP4 To WMP



Great way to circumvent the procurement risk



MKV To WMV



QTP Descriptive language experience



For the B / S structure, to UNDERSTAND the point



FTP operation of COMMON sense



Robin Li Baidu executives leave: "make money the most important"



Sunday, October 10, 2010

Mac can become the third money-maker Jobs



"Business Week" recently published an article that those who have iPod or iPhone's enterprise workers want configure Apple's Mac computers office, no doubt that the corporate PC market, Apple's military expansion and provided an unprecedented opportunity, and Apple is ready for this? Mac iPod and iPhone can continue after a third money-maker of the Jobs?

In the first quarter of this year, Apple Mac sales worldwide increased by more than 51% over the same period last year, exceeded all analyst expectations, the growth rate of almost the entire computer industry more than three times the average. IPod and iPhone products in the promotion of the two, Apple's annual income from 5.4 billion in 2002 to rise rapidly to 24 billion U.S. dollars last year. In the past five years, Apple's stock has risen 23 times Biao, the company's market capitalization reached 154 billion U.S. dollars, more than a technology giant Hewlett-Packard, Intel and Dell.

Once a favorite of students and artists Mac is becoming the first choice for consumers. Apple is expected, despite the current economic environment facing the downturn, but the rapid growth of demand will lead to its second-quarter revenue rose 33% to 72 billion U.S. dollars. At the same time, the needs of business users on the Mac also began to grow. Those who like innovative staff began to require employers to configure the Mac computers in the office. Market research firm Yankee Group's 250 types of enterprises surveyed, found that 87% of the company in his office allocation of some Apple computers, two years earlier to 48%.

For those staff, they are likely to buy the iPod or iPhone, but placed in the home Mac, back in the office of course, reluctant to switch to the Windows interface. These staff tired of Windows, Microsoft is not doing to well, but Apple's Mac really cool. Even IT giants IBM and Cisco are conducting tests to determine whether the Office should be Mac introduced. The search giant several years ago to allow employees to freely choose their work computer.

The other companies will surely follow. A large computer services company's chief information officer, said his staff recently received 25 e-mail, asked Mac computers in the office profile. However, taking into account the need for additional staff to maintain the Mac computer, the chief information officer rejected these demands. Same router manufacturer Juniper's chief information officer also received a staff office proposed configuration requirements Mac computer. To this end the company launched a test on the Mac, 600 Juniper staff equipped with Mac computers, to test the cost of maintenance costs. As long as the cost of not too high, the company plans release the power of the computer staff selection is expected to at least 25% of employees would choose Mac.

In this process, Steve Jobs did not spend a penny of promotion costs. Of the last century 80's, Apple in the enterprise PC market can be said is defeated, for 1997, Jobs returned to Apple after the company decided to focus on consumers and students for the PC-group market. Therefore, the company did not target the enterprise market sales and technical support teams.

Jobs declined to comment on. But he has previously said that Apple is more focused on consumer-oriented PC market, he believes it is very difficult for any company to meet the business needs of users and consumers.

According to market research firm IDC data, PC-year corporate market was 150 billion U.S. dollars, Apple accounted for only 2.19% of the share. So long as Apple's market share in this a way to enhance revenue will increase 1.5 billion U.S. dollars, which will drive Apple's fiscal 2008 profit forecast 11.5% growth will be more than 5 billion U.S. dollars. There is no doubt that Apple's market worth a try.

Apple's iPhone, will be the stepping stone into the corporate office market, it is an apple to develop a clear plan to one of the products into the enterprise market. Apple plans in June this year to upgrade the software on the iPhone, so with companies such as Microsoft Exchange mail systems work better together, in addition to allow business users to create custom iPhone applications, such as inventory checks, Apple said it has been more than 160 major companies are testing the software co.

Gartner Group research analyst, said the discussions on the iPhone began to encourage businesses should also consider whether the introduction of Mac computers. At least in the corporate R & D department should introduce more of the Mac computer, because iPhone application development only in the Mac on.

At the same time, Microsoft's latest operating system Vista has to a certain extent, helped Apple's favor. Microsoft took five years of development of the operating system it is possible to become one of the best works of the failure of the system is not only a lack of compelling new features, and requires users to buy more expensive PC, hardware, and a small problem after another. 90% of office workers are still in use XP, but Microsoft plans to June 30 this year, PC makers to stop XP system, no doubt that Apple has created a great opportunity.

But Microsoft said that Apple tried to breakthrough in the enterprise PC market is not easy, because for the enterprise market, we must consume enormous financial resources to build a sales and technical support departments, and Apple's secrecy mechanisms will hinder and business users to establish a strong relations. More importantly, Apple can not modify the product design to meet the different needs of business users.

However, with the development of network technology to the next 10 years, Windows and the Mac will no longer be competition between. By then, most corporate users of computing tasks will be achieved through the network, not demand a particular Windows application software, the Internet will serve as a platform to replace Windows.

With the harmonious relationship between business users, Apple is also made no small progress. Because Mac computers also use Intel's chips, which can also run Microsoft's Windows system, this no doubt makes the enterprise users to migrate to the Mac platform, with not as difficult. In addition, Mac uses virtualization software technology that can run Mac OS and Windows systems and can easily switch. This feature is also prompted some customers to use Mac computers power.

However, the large corporate market, Apple's Mac computers have encountered greater resistance. Because these companies have more complex IT systems, the introduction of Mac training and maintenance costs will increase, in addition to software restrictions is an important reason, such as SAP applications can not run in Mac.

In addition, Apple's corporate culture is also a further expansion in the enterprise market, the challenges to be faced. Apple is well known for confidentiality, but business users need to know that their products are the next few years the evolution of line, no doubt Apple will not share this information, in addition to the necessary partners. In addition, PC-market, business users want to establish a close working relationship, and Apple is difficult to do, because almost all of its sales are conducted through the Internet.

The price is also an important factor. Current PC, the average price has dropped to 963 U.S. dollars, while the Mac, the average price of 1526 U.S. dollars, and Apple's relatively inexpensive desktop iMac with a built-in display mode, which is for the budget-sensitive business users indeed a problem, because the display replacement time should be longer than the host.

Industry analysts pointed out, Mac can continue after the iPod and iPhone, as Jobs's third money-maker, which depends largely on Jobs's decision. His position as the original, Apple iTunes will not sell the film, not to enter the mobile phone market. And now all changed. Although Apple can ignore the corporate PC market, but several years later when Apple's search for new sources of growth which is very attractive.









Recommended links:



SWsoft Virtuozzo: MAVERICK chaser



Struts framework in the Session object TO create and control



Screen SAVERS Shop



TD 3 Tender Cover Is The Key To Solve



VOB To SWF



College Job: Workplace Rules Are Familiar With The Key



Beautiful call, XP Mac OS PERFECT clone



Guide Cursors And Fonts



FLV To Zune



Lucent China's Revenue Fell 9 Longa Marriage To Be Laid Off Thousands



Dressing appropriately, moderate conversation interview etiquette all captures



Fixing Your Windows Registry With Top Registry



SA118 Chinese translation 2



U.S. will send experts want to increase overseas trade negotiations to combat piracy weight



3GP to MPEG