Inside com电子书

Fnoopy 2001-10-07 10:59:57
哪位有inside com电子书呀,最好是英文版。我尝试过超星的中文简体版,笨重;还有chm格式的中文繁体版,无奈简体2000下打不开。
谢谢
请邮fnoopyf@163.net联系。
...全文
87 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
prog_st 2001-10-08
  • 打赏
  • 举报
回复
URL http://yuyu.6to23.com/book/inside_com.zip

引用页 http://www.yuyux.com/bookcity/html/404.htm
Fnoopy 2001-10-07
  • 打赏
  • 举报
回复
谢谢。
Spring.Boot.in.Action.2015.12.pdfFor online information and ordering of this and other manning books, please visit www.manning.com.thepublisheroffersdiscountsonthisbookwhenorderedinquantity For more information, please contact Special sales department Manning publications co 20 Baldwin Road PO BoX 761 Shelter island. ny11964 Emailorders@manning.com @2016 by manning Publications Co. All rights reserved No part of this publication may be reproduced, stored in a retrieval system, or transmitted,in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and manning Publications was aware of a trademark claim, the designations have been printed in initial caps ll Recognizing the importance of preserving what has been written, it is Mannings policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine Manning publications co Development editor: Cynthia Kane 20 Baldwin Road Technical development editor: Robert casazza PO BoX 761 Copyeditor: Andy Carroll Shelter island. ny11964 Proofreader: Corbin Collins Technical p der John Guthrie Typesetter: Gordan Salinovic Cover designer: Marija Tudor ISBN9781617292545 Printed in the united states of america 12345678910-EBM-201918171615 contents reword vii pre eface 2x about this book xii acknowledgments xu Bootstarting Spring I 1. 1 Spring rebooted Taking a fresh look at spring 2. Examining spring Boot essentials 4 What Spring Boot isn't 7 1.2 Getting started with Spring boot 8 Installing the spring boot cli 8 Initializing a spring boot project with Spring Initializr 12 3 Summary 22 Developing your first Spring Boot application 23 2.1 Putting spring boot to work 24 Examining a newly initialized spring boot project 26 Dissecting Bc iect build 30 2.2 USing starter dependencies 33 Specifying facet-based dependencies 34. Overriding starter transitive dependencies 35 CONTENTS 2.8 USing automatic configuration 37 Focusing on application functionality 37. Running the application 45. What just happened? 45 2.4 Summary 48 Customizing configuration 49 8.1 Overriding Spring Boot auto-configuration 50 Securing the application 50. Creating a custom security configuration 51. Taking another peek under the covers of auto-configuration55 8.2 Externalizing configuration with properties 57 Fine-tuning auto-configuration 58. Externally configuring application beans 64. Configuring with profiles 69 8.8 Customizing application error pages 71 3.4 Summary 74 Testing with Spring Boot 76 4.1 Integration testing auto-configuration 77 4.2 Testing web applications 79 Mocking spring MvC 80- Testing web security 83 4.3 Testing a running application 86 Starting the server on a random port 87. Testing HTML pages with selenium 88 4.4 Summary 90 Getting Groovy with the spring Boot CLI 92 5.1 Developing a Spring Boot CLI application 93 Setting up the cli project 93 Eliminating code noise with Groovy 94. What just happened? 98 5.2 Grabbing dependencies 100 Overriding default dependency versions 101. Adding dependency repositories 102 5.8 Running tests with the CLI 102 5.4 Creating a deployable artifact 105 5.5 Summary 106 CONTENTS 6 Applying Grails in Spring Boot 107 1 Using gorm for data persistence 108 2 Defining views with groovy server pages 113 6.3 Mixing spring boot with grails 3 115 Creating a new grails project 116 Defining the domain 118 Writing a grails controller 119. Creating the view 120 6.4 Summary 123 Taking a peek inside with the Actuator 124 7.1 Exploring the actuator's endpoints 125 Viewing configuration details 126. Tapping runtime metrics 133 Shutting down the application 139. Fetching application information 140 7.2 Connecting to the Actuator remote shell 141 Viewing the autoconfig report 142. Listing application beans 143 Watching application metrics 144.Invoking actuator endpoints 145 7. 3 Monitoring your application with JMX 146 7.4 Customizing the Actuator 148 Changing endpoint Ds 148 Enabling and disabling endpoints 149 Adding custom metrics and gauges 149- Creating a custom trace repository 153 Plugging in custom health indicators 155 7.5 Securing Actuator endpoints 156 7.6 Summary 159 8 Deploying Spring Boot applications 160 8.1 Weighing deployment options 161 8.2 Deploying to an application server 162 Building a WaRfile 162 Creating a production profile Enabling database migration 168 8.3 Pushing to the cloud 173 Deploying to Cloud Foundry 173 Deploying to Heroku 177 8. Summary 180 appendix a spring Boot developer Tools 187 appendix b spring Boot starters 188 appendix c Configuration properties 195 appendix d spring boot dependencies 232 index 243 In the spring of 2014, the Delivery Engineering team at Netflix set out to achieve a lofty goal: enable end-to-end global continuous delivery via a software platform that facilitates both extensibility and resiliency. my team had previously built two different applications attempting to address Netflix's delivery and deployment needs, but both were beginning to show the telltale signs of monolith-ness and neither met the goals of flexibility and resiliency. What's more, the most stymieing effect of these monolithic applications was ultimately that we were unable to keep pace with our partner's inno- vation. Users had begun to move around our tools rather than with them It became apparent that if we wanted to provide real value to the company and rap- idly innovate, we needed to break up the monoliths into small, independent services that could be released at will. Embracing a microservice architecture gave us hope that we could also address the twin goals of flexibility and resiliency. but we needed to do it on a credible foundation where we could count on real concurrency, legitimate moni- toring, reliable and easy service discovery, and great runtime performance With the jVM as our bedrock, we looked for a framework that would give us rapid velocity and steadfast operationalization out of the box. We zeroed in on Spring Boot Spring Boot makes it effortless to create Spring-powered, production-ready ser- vices without a lot of code! Indeed, the fact that a simple Spring Boot Hello World application can fit into a tweet is a radical departure from what the same functionality required on the vm only a few short years ago. Out-of-the-box nonfunctional features like security, metrics, health-checks, embedded servers, and externalized configura tion made boot an easy choice for us FOREWORD Yet, when we embarked on our Spring boot journey solid documentation was hard to come by. Relying on source code isnt the most joyful manner of figuring out how to properly leverage a frameworks features It's not surprising to see the author of mannings venerable Spring in Action take on the challenge of concisely distilling the core aspects of working with Spring Boot into another cogent book. Nor is it surprising that Craig and the Manning crew have done another tremendously wonderful job! Spring Boot in Action is an easily readable book, as weve now come to expect from Craig and manning From chapter Is attention-getting introduction to Boot and the now legend ary 9Oish-character tweetable Boot application to an in-depth analysis of Boots Actuator in chapter 7, which enables a host of auto-magical operational features required for any production application, Spring Boot in Action leaves no stone unturned. Indeed, for me, chapter 7's deep dive into the Actuator answered some of the lingering questions I've had in the back of my head since picking up Boot well over a year ago. Chapter 8s thor- ough examination of deployment options opened my eyes to the simplicity of cloud Foundry for cloud deployments. One of my favorite chapters is chapter 4, where Craig explores the many powerful options for easily testing a Boot application. From the get- o, I was pleasantly surprised with some of Springs testing features, and boot takes g advantage of them nicely As I've publicly stated before, Spring Boot is just the kind of framework the Java community has been seeking for over a decade. Its easy-to-use development features and out-of-the-box operationalization make java development fun again I,m pleased to report that Spring and spring boot are the foundation of Netflix's new continuous delivery platform. What's more, other teams at Netflix are following the same path because they too see the myriad benefits of boot It's with equal parts excitement and passion that I absolutely endorse craigs book as the easy-to-digest and fun-to-read Spring boot documentation the Java community has been waiting for since Boot took the community by storm. Craigs accessible writ- ing style and sweeping analysis of boot's core features and functionality will surely leave readers with a solid grasp of Boot(along with a joyful sense of awe for it) Keep up the great work Craig Manning Publications, and all the brilliant develop ers who have made spring boot what it is today each one of you has ensured a bright future for the JV ANDREW GLOVER MANAGER, DELIVERY ENGINEERING AT NETFLIX preface At the 1964 New York World's Fair, Walt Disney introduced three groundbreaking attractions:"“it' s a small world,”“ Great Moments with mr. Lincoln," and the“ Carouse of Progress " All three of these attractions have since moved into disneyland and walt Disney world, and you can still see them today My favorite of these is the Carousel of Progress. Supposedly, it was one of Walt Disneys favorites too. It's part ride and part stage show where the seating area rotates around a center area featuring four stages. Each stage tells the story of a family at different time periods of the 20th century-the early 1900s, the 1920s the 1940s, and recent times-highlighting the technology advances in that time period The story of innovation is told from a hand-cranked washing machine, to electric lighting and radio, to automatic dishwashers and television, to computers and voice-activated appliances In every act, the father (who is also the narrator of the show)talks about the latest inventions and says "It cant get any better only to discover that in fact, it does get better in the next act as technology progresses Although Spring doesn't have quite as long a history as that displayed in the Car- ousel of Progress, I feel the same way about Spring as"Progress Dad felt about the 20th century. Each and every Spring application seems to make the lives of developers so much better. Just looking at how Spring components are declared and wired together, we can see the following progression over the history of Spring
《数据挖掘实用机器学习技术》(原书第2版)介绍数据挖掘的基本理论与实践方法。主要内容包括:各种模型(决策树、关联规则、线性模型、聚类、贝叶斯网以及神经网络)以及在实践中的运用,所存在缺陷的分析。安全地清理数据集、建立以及评估模型的预测质量的方法,并且提供了一个公开的数据挖掘工作平台Weka。Weka系统拥有进行数据挖掘任务的图形用户界面,有助于理解模型,是一个实用并且深受欢迎的工具。 编辑推荐 正如所有受到商业注目的新兴技术一样,数据挖掘的运用也是极其多样化的。言过其实的报导声称可以建立算法,在数据的海洋里发现秘密。但事实上机器学习中没有魔术,没有隐藏的力量,没有炼金术。有的只是一些可以将有用的信息从原始数据中提炼出来的清晰明了的实用技术。《数据挖掘实用机器学习技术》(原书第2版)叙述了这些技术并展示了它们是如何工作的。   《数据挖掘实用机器学习技术》(原书第2版)对1999年的初版做了重大的改动。虽说核心概念没有变化,但《数据挖掘实用机器学习技术》(原书第2版)做了更新,反映出过去五年的变化。《数据挖掘实用机器学习技术》(原书第2版)提供了机器学习理论概念的完整基础,此外还对实际工作中应用的相关工具和技术提了一些建议。   《数据挖掘实用机器学习技术》(原书第2版)逻辑严密、内容翔实、极富实践性,适合作为高等学校本科生或研究生的教材,也可供相关技术人员参考。 作者简介 作者:(新西兰)威滕 弗兰克 Ian H.Witten,新西兰怀卡托大学计算机科学系教授,ACM和新西兰皇家学会成员,曾荣获2004年国际信息处理研究协会(IFIP)颁发的Namur奖项。他的著作包括《Managing Gigabytes:Compressirlg and Indexing Documents and Images》、《How to Build a Digital Library》以及众多的期刊和学会文章。 目录 出版者的话 专家指导委员会 译者序 中文版前言 序 前言 第一部分 机器学习工具与技术 第1章 绪论 1.1数据挖掘和机器学习 1.1.1描述结构模式 1.1.2机器学习 1.1.3数据挖掘 1.2简单的例子:天气问题和其他 1.2.1天气问题 1.2.2隐形眼镜:一个理想化的问题 1.2.3鸢尾花:一个经典的数值型数据集 1.2.4CPU性能:介绍数值预测 1.2.5劳资协商:一个更真实的例子 1.2.6大豆分类:一个经典的机器学习的成功例子 1.3应用领域 1.3.1决策包含评判 1.3.2图像筛选 1.3.3负载预测 1.3.4诊断 1.3.5市场和销售 1.3.6其他应用 1.4机器学习和统计学 1.5用于搜索的概括 1.5.1枚举概念空间 1.5.2偏差 1.6数据挖掘和道德 1.7补充读物 第2章 输入:概念、实例和属性 2.1概念 2.2样本 2.3属性 2.4输入准备 2.4.1数据收集 2.4.2 ARFF格式 2.4.3稀疏数据 2.4.4属性类型 2.4.5残缺值 2.4.6不正确的值 2.4.7了解数据 2.5补充读物 第3章 输出:知识表达 3.1决策表 3.2决策树 3.3分类规则 3.4关联规则 3.5包含例外的规则 3.6包含关系的规则 3.7数值预测树 3.8基于实例的表达 3.9聚类 3.10补充读物 第4章 算法:基本方法 4.1推断基本规则 4.1.1残缺值和数值属性 4.1.2讨论 4.2统计建模 4.2.1残缺值和数值属性 4.2.2用于文档分类的贝叶斯模型 4.2.3讨论 4.3分治法:创建决策树 4.3.1计算信息量 4.3.2高度分支属性 4.3.3讨论 …… 第5章 可信度:评估机器学习结果 第6章 实现:真正的机器学习方案 第7章 转换:处理输入和输出 第8章 继续:扩展和应用 第二部分 Weka机器学习平台 第9章 weka简介 第10章 Explorer界面 第11章 Knowledge Flow界面 第12章 Experimenter界面 第13章 命令行界面 第14章 嵌入式机器学习 第15章 编写新学习方案 参考文献 索引 Editorial Reviews Review "This book presents this new discipline in a very accessible form: both as a text to train the next generation of practitioners and researchers, and to inform lifelong learners like myself. Witten and Frank have a passion for simple and elegant solutions. They approach each topic with this mindset, grounding all concepts in concrete examples, and urging the reader to consider the simple techniques first, and then progress to the more sophisticated ones if the simple ones prove inadequate. If you have data that you want to analyze and understand, this book and the associated Weka toolkit are an excellent way to start." - From the foreword by Jim Gray, Microsoft Research "It covers cutting-edge, data mining technology that forward-looking organizations use to successfully tackle problems that are complex, highly dimensional, chaotic, non-stationary (changing over time), or plagued by. The writing style is well-rounded and engaging without subjectivity, hyperbole, or ambiguity. I consider this book a classic already!" - Dr. Tilmann Bruckhaus, StickyMinds.com Book Description Highly anticipated second edition of the highly-acclaimed reference on data mining and machine learning. Product Description As with any burgeoning technology that enjoys commercial attention, the use of data mining is surrounded by a great deal of hype. Exaggerated reports tell of secrets that can be uncovered by setting algorithms loose on oceans of data. But there is no magic in machine learning, no hidden power, no alchemy. Instead there is an identifiable body of practical techniques that can extract useful information from raw data. This book describes these techniques and shows how they work. The book is a major revision of the first edition that appeared in 1999. While the basic core remains the same, it has been updated to reflect the changes that have taken place over five years, and now has nearly double the references. The highlights for the new edition include thirty new technique sections; an enhanced Weka machine learning workbench, which now features an interactive interface; comprehensive information on neural networks; a new section on Bayesian networks; plus much more. * Algorithmic methods at the heart of successful data mining-including tried and true techniques as well as leading edge methods * Performance improvement techniques that work by transforming the input or output * Downloadable Weka, a collection of machine learning algorithms for data mining tasks, including tools for data pre-processing, classification, regression, clustering, association rules, and visualization-in a new, interactive interface From the Back Cover This book presents this new discipline in a very accessible form: both as a text to train the next generation of practitioners and researchers, and to inform lifelong learners like myself. Witten and Frank have a passion for simple and elegant solutions. They approach each topic with this mindset, grounding all concepts in concrete examples, and urging the reader to consider the simple techniques first, and then progress to the more sophisticated ones if the simple ones prove inadequate. If you have data that you want to analyze and understand, this book and the associated Weka toolkit are an excellent way to start. --From the foreword by Jim Gray, Microsoft Research As with any burgeoning technology that enjoys commercial attention, the use of data mining is surrounded by a great deal of hype. Exaggerated reports tell of secrets that can be uncovered by setting algorithms loose on oceans of data. But there is no magic in machine learning, no hidden power, no alchemy. Instead there is an identifiable body of practical techniques that can extract useful information from raw data. This book describes these techniques and shows how they work. The book is a major revision of the first edition that appeared in 1999. While the basic core remains the same, it has been updated to reflect the changes that have taken place over five years, and now has nearly double the references. The highlights for the new edition include thirty new technique sections; an enhanced Weka machine learning workbench, which now features an interactive interface; comprehensive information on neural networks; a new section on Bayesian networks; plus much more. Offering a thorough grounding in machine learning concepts as well as practical advice on applying the tools and techniques, inside you'll find: + Algorithmic methods at the heart of successful data mining-including tried and true techniques as well as leading edge methods; + Performance improvement techniques that work by transforming the input or output; + Downloadable Weka, a collection of machine learning algorithms for data mining tasks, including tools for data pre-processing, classification, regression, clustering, association rules, and visualization-in a new, interactive interface. About the Author Ian H. Witten is a professor of computer science at the University of Waikato in New Zealand. He directs the New Zealand Digital Library research project. His research interests include information retrieval, machine learning, text compression, and programming by demonstration. He received an MA in Mathematics from Cambridge University, England; an MSc in Computer Science from the University of Calgary, Canada; and a PhD in Electrical Engineering from Essex University, England. He is a fellow of the ACM and of the Royal Society of New Zealand. He has published widely on digital libraries, machine learning, text compression, hypertext, speech synthesis and signal processing, and computer typography. He has written several books, the latest being Managing Gigabytes (1999) and Data Mining (2000), both from Morgan Kaufmann. Eibe Frank is a researcher in the Machine Learning group at the University of Waikato. He holds a degree in computer science from the University of Karlsruhe in Germany and is the author of several papers, both presented at machine learning conferences and published in machine learning journals. http://www.amazon.com/Data-Mining-Practical-Techniques-Management/dp/0120884070/ref=sr_1_1?ie=UTF8&s=books&qid=1277222917&sr=8-1 http://www.amazon.cn/gp/product/B00114B30K?ver=gp&qid=1277222740&ref_=sr_1_3&sr=8-3&s=books
在一小时内学会 C#。使用例程,简单却完整的探索 C# 语言的构造和特点。本文特别适合有 C++ 基础却没有太多精力学习 C# 的读者。 关于作者 Aisha Ikram 我现在在英国一家软件公司任技术带头人。我是计算机科学的硕士。我主要使用 .NET 1.1/2.0, C#, VB.NET, ASP.NET, VC++ 6, MFC, ATL, COM/DCOM, SQL Server 2000/2005等。最近我在学习 .NET 3.x 的全部内容。我的免费源代码和文章网站是 http://aishai.netfirms.com 职业:团队带头人 位置:英国 简介 C# 是一种具有 C++ 特性,Java 样式及 BASIC 快速建模特性的编程语言。如果你已经知晓 C++ 语言,本文将在不到一小时的时间内带你快速浏览 C# 的语法。如果熟悉 Java 语言,Java 的编程结构、打包和垃圾回收的概念肯定对你快速学习 C# 大有帮助。所以我在讨论 C# 语言构造的时候会假设你知道 C++。 本文通过一系列例程以简短但全面的方式讨论了 C# 语言构造和特性,所以你仅需略览代码片刻,即可了解其概念。 注意:本文不是为 C# 宗师而写。有很多初学者的 C# 文章,这只是其中之一。 接下来关于 C# 的讨论主题: ? 编程结构 ? 命名空间 ? 数据类型 ? 变量 ? 运算符与表达式 ? 枚举 ? 语句 ? 类与结构 ? 修饰符 ? 属性 ? 接口 ? 函数参数 ? 数组 ? 索引器 ? 装箱与拆箱 ? 委托 ? 继承与多态 以下主题不会进行讨论: ? C++ 与 C# 的共同点 ? 诸如垃圾回收、线程、文件处理等概念 ? 数据类型转换 ? 异常处理 ? .NET 库 编程结构 和 C++ 一样,C# 是大小写敏感的。半角分号(;)是语句分隔符。和 C++ 有所区别的是,C# 中没有单独的声明(头)和实现(CPP)文件。所有代码(类声明和实现)都放在扩展名为 cs 的单一文件中。 看看 C# 中的 Hello World 程序。 复制内容到剪贴板 代码: using System; namespace MyNameSpace { class HelloWorld { static void Main(string[] args) { Console.WriteLine ("Hello World"); } } } C# 中所有内容都打包在类中,而所有的类又打包在命名空间中(正如文件存与文件夹中)。和 C++ 一样,有一个主函数作为你程序的入口点。C++ 的主函数名为 main,而 C# 中是大写 M 打头的 Main。 类块或结构定义之后没有必要再加一个半角分号。C++ 中是这样,但 C# 不要求。 命名空间 每个类都打包于一个命名空间。命名空间的概念和 C++ 完全一样,但我们在 C# 中比在 C++ 中更加频繁的使用命名空间。你可以用点(.)定界符访问命名空间中的类。上面的 Hello World 程序中,MyNameSpace 是其命名空间。 现在思考当你要从其他命名空间的类中访问 HelloWorld 类。 复制内容到剪贴板 代码: using System; namespace AnotherNameSpace { class AnotherClass { public void Func() { Console.WriteLine ("Hello World"); } } } 现在在你的 HelloWorld 类中你可以这样访问: 复制内容到剪贴板 代码: using System; using AnotherNameSpace; // 你可以增加这条语句 namespace MyNameSpace { class HelloWorld { static void Main(string[] args) { AnotherClass obj = new AnotherClass(); obj.Func(); } } } 在 .NET 库中,System 是包含其他命名空间的顶层命名空间。默认情况下存在一个全局命名空间,所以在命名空间外定义的类直接进到此全局命名空间中,因而你可以不用定界符访问此类。 你同样可以定义嵌套命名空间。 Using #include 指示符被后跟命名空间名的 using 关键字代替了。正如上面的 using System。System 是最基层的命名空间,所有其他命名空间和类都包含于其中。System 命名空间中所有对象的基类是 Object。 变量 除了以下差异,C# 中的变量几乎和 C++ 中一样: 1. C# 中(不同于 C++)的变量,总是需要你在访问它们前先进行初始化,否则你将遇到编译时错误。故而,不可能访问未初始化的变量。 2. 你不能在 C# 中访问一个“挂起”指针。 3. 超出数组边界的表达式索引值同样不可访问。 4. C# 中没有全局变量或全局函数,取而代之的是通过静态函数和静态变量完成的。 数据类型 所有 C# 的类型都是从 object 类继承的。有两种数据类型: 1. 基本/内建类型 2. 用户定义类型 以下是 C# 内建类型的列表: 类型 字节 描述 byte 1 unsigned byte sbyte 1 signed byte short 2 signed short ushort 2 unsigned short int 4 signed integer uint 4 unsigned integer long 8 signed long ulong 8 unsigned long float 4 floating point number double 8 double precision number decimal 8 fixed precision number string - Unicode string char - Unicode char bool true, false boolean 注意:C# 的类型范围和 C++ 不同。例如:long 在 C++ 中是 4 字节而在 C# 中是 8 字节。bool 和 string 类型均和 C++ 不同。bool 仅接受真、假而非任意整数。 用户定义类型文件包含: 1. 类 (class) 2. 结构(struct) 3. 接口(interface) 以下类型继承时均分配内存: 1. 值类型 2. 参考类型 值类型 值类型是在堆栈中分配的数据类型。它们包括了: ? 除字符串,所有基本和内建类型 ? 结构 ? 枚举类型 引用类型 引用类型在堆(heap)中分配内存且当其不再使用时,将自动进行垃圾清理。和 C++ 要求用户显示创建 delete 运算符不一样,它们使用新运算符创建,且没有 delete 运算符。在 C# 中它们自动由垃圾回收系统回收。 引用类型包括: ? 类 ? 接口 ? 集合类型如数组 ? 字符串 枚举 C# 中的枚举和 C++ 完全一样。通过关键字 enum 定义。 例子: 复制内容到剪贴板 代码: enum Weekdays { Saturday, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday } 类与结构 除了内存分配的不同外,类和结构就和 C++ 中的情况一样。类的对象在堆中分配,并使用 new 关键字创建。而结构是在栈(stack)中进行分配。C# 中的结构属于轻量级快速数据类型。当需要大型数据类型时,你应该创建类。 例子: 复制内容到剪贴板 代码: 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 SetMonth(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) { } ... } 属性 如果你熟悉 C++ 面向对象的方法,你一定对属性有自己的认识。对 C++ 来说,前面例子中 Date 类的属性就是 day、month 和 year,而你添加了 Get 和 Set 方法。C# 提供了一种更加便捷、简单而又直接的属性访问方式。 所以上面的类应该写成这样: 复制内容到剪贴板 代码: using System; class Date { public int Day{ get { return day; } set { day = value; } } int day; public int Month{ get { 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; } } 这里是你 get 和 set 属性的方法: 复制内容到剪贴板 代码: 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); } } 修饰符 你必须知道 C++ 中常用的 public、private 和 protected 修饰符。我将在这里讨论一些 C# 引入的新的修饰符。 readonly readonly 修饰符仅用于修饰类的数据成员。正如其名字说的,一旦它们已经进行了写操作、直接初始化或在构造函数中对其进行了赋值,readonly 数据成员就只能对其进行读取。readonly 和 const 数据成员不同之处在于 const 要求你在声明时进行直接初始化。看下面的例程: 复制内容到剪贴板 代码: class MyClass { const int constInt = 100; //直接进行 readonly int myInt = 5; //直接进行 readonly int myInt2; public MyClass() { myInt2 = 8; //间接进行 } public Func() { myInt = 7; //非法 Console.WriteLine(myInt2.ToString()); } } sealed 带有 sealed 修饰符的类不允许你从它继承任何类。所以如果你不想一个类被继承,你可以对该类使用 sealed 关键字。 复制内容到剪贴板 代码: sealed class CanNotbeTheParent { int a = 5; } unsafe 你可以使用 unsafe 修饰符在 C# 中定义一个不安全上下文。在不安全上下文中,你可以插入不安全代码,如 C++ 的指针等。参见以下代码: 复制内容到剪贴板 代码: public unsafe MyFunction( int * pInt, double* pDouble) { int* pAnotherInt = new int; *pAnotherInt = 10; pInt = pAnotherInt; ... *pDouble = 8.9; } 接口 如果你有 COM 的思想,你马上就知道我在说什么了。接口是只包含函数签名而在子类中实现的抽象基类。在 C# 中,你可以用 interface 关键字声明这样的接口类。.NET 就是基于这样的接口的。C# 中你不能对类进行多重继承——这在 C++ 中是允许的。通过接口,多重继承的精髓得以实现。即你的子类可以实现多重接口。(译注:由此可以实现多重继承) 复制内容到剪贴板 代码: using System; interface myDrawing { int originx { get; set; } int originy { get; set; } void Draw(object shape); } class Shape: myDrawing { int OriX; int OriY; public int originx { get{ return OriX; } set{ OriX = value; } } public int originy { get{ return OriY; } set{ OriY = value; } } public void Draw(object shape) { ... // 做要做的事 } // 类自身的方法 public void MoveShape(int newX, int newY) { ..... } } 数组 数组在 C# 中比 C++ 中要高级很多。数组分配于堆中,所以是引用类型的。你不能访问数组边界外的元素。所以 C# 防止你引发那种 bug。同时也提供了迭代数组元素的帮助函数。foreach 是这样的迭代语句之一。C++ 和 C# 数组的语法差异在于: 方括号在类型后面而不是在变量名后面 创建元素使用 new 运算符 C# 支持一维、多维和交错数组(数组的数组) 例子: 复制内容到剪贴板 代码: int[] array = new int[10]; // int 型一维数组 for (int i = 0; i < array.Length; i++) array = i; int[,] array2 = new int[5,10]; // int 型二维数组 array2[1,2] = 5; int[,,] array3 = new int[5,10,5]; // int 型三维数组 array3[0,2,4] = 9; int[][] arrayOfarray = new int[2]; // int 型交错数组 - 数组的数组 arrayOfarray[0] = new int[4]; arrayOfarray[0] = new int[] {1,2,15}; 索引器 索引器用于书写一个可以通过使用 [] 像数组一样直接访问集合元素的方法。你所需要的只是指定待访问实例或元素的索引。索引器的语法和类属性语法相同,除了接受作为元素索引的输入参数外。 例子: 注意:CollectionBase 是用于建立集合的库类。List 是 CollectionBase 中用于存放集合列表的受保护成员。 复制内容到剪贴板 代码: class Shapes: CollectionBase { public void add(Shape shp) { List.Add(shp); } //indexer public Shape this[int index] { get { return (Shape) List[index]; } set { List[index] = value ; } } } 装箱/拆箱 装箱的思想在 C# 中是创新的。正如前面提到的,所有的数据类型,无论是内建的还是用户定义的,都是从 System 命名空间的基类 object 继承的。所以基础的或是原始的类型打包为一个对象称为装箱,相反的处理称为拆箱。 例子: 复制内容到剪贴板 代码: class Test { static void Main() { int myInt = 12; object obj = myInt ; // 装箱 int myInt2 = (int) obj; // 拆箱 } } 例程展示了装箱和拆箱两个过程。一个 int 值可以被转换为对象,并且能够再次转换回 int。当某种值类型的变量需要被转换为一个引用类型时,便会产生一个对象箱保存该值。拆箱则完全相反。当某个对象箱被转换回其原值类型时,该值从箱中拷贝至适当的存储空间。 函数参数 C# 中的参数有三种类型: 1. 按值传递/输入参数 2. 按引用传递/输入-输出参数 3. 输出参数 如果你有 COM 接口的思想,而且还是参数类型的,你会很容易理解 C# 的参数类型。 按值传递/输入参数 值参数的概念和 C++ 中一样。传递的值复制到了新的地方并传递给函数。 例子: 复制内容到剪贴板 代码: SetDay(5); ... void SetDay(int day) { .... } 按引用传递/输入-输出参数 C++ 中的引用参数是通过指针或引用运算符 & 传递的。C# 中的引用参数更不易出错。你可以传递一个引用地址,你传递一个输入的值并通过函数得到一个输出的值。因此引用参数也被称为输入-输出参数。 你不能将未初始化的引用参数传递给函数。C# 使用关键字 ref 指定引用参数。你同时还必须在传递参数给要求引用参数的函数时使用关键字 ref。 例子: 复制内容到剪贴板 代码: int a= 5; FunctionA(ref a); // 使用 ref,否则将引发编译时错误 Console.WriteLine(a); // 打印 20 复制内容到剪贴板 代码: void FunctionA(ref int Val) { int x= Val; Val = x* 4; } 输出参数 输出参数是只从函数返回值的参数。输入值不要求。C# 使用关键字 out 表示输出参数。 例子: 复制内容到剪贴板 代码: int Val; GetNodeValue(Val); 复制内容到剪贴板 代码: bool GetNodeValue(out int Val) { Val = value; return true; } 参数和数组的数量变化 C# 中的数组使用关键字 params 进行传递。一个数组类型的参数必须总是函数最右边的参数。只有一个参数可以是数组类型。你可以传送任意数量的元素作为数组类型的参数。看了下面的例子你可以更好的理解: 注意:使用数组是 C# 提供用于可选或可变数量参数的唯一途径。 例子: 复制内容到剪贴板 代码: void Func(params int[] array) { Console.WriteLine("number of elements {0}", array.Length); } 复制内容到剪贴板 代码: Func(); // 打印 0 Func(5); // 打印 1 Func(7,9); // 打印 2 Func(new int[] {3,8,10}); // 打印 3 int[] array = new int[8] {1,3,4,5,5,6,7,5}; Func(array); // 打印 8 运算符与表达式 运算符和表达式跟 C++ 中完全一致。然而同时也添加了一些新的有用的运算符。有些在这里进行了讨论。 is 运算符 is 运算符是用于检查操作数类型是否相等或可以转换。is 运算符特别适合用于多态的情形。is 运算符使用两个操作数,其结果是布尔值。参考例子: 复制内容到剪贴板 代码: void function(object param) { if(param is ClassA) //做要做的事 else if(param is MyStruct) //做要做的事 } } as 运算符 as 运算符检查操作数的类型是否可转换或是相等(as 是由 is 运算符完成的),如果是,则处理结果是已转换或已装箱的对象(如果操作数可以装箱为目标类型,参考 装箱/拆箱)。如果对象不是可转换的或可装箱的,返回值为 null。看看下面的例子以更好的理解这个概念。 复制内容到剪贴板 代码: Shape shp = new Shape(); Vehicle veh = shp as Vehicle; // 返回 null,类型不可转换 Circle cir = new Circle(); Shape shp = cir; Circle cir2 = shp as Circle; //将进行转换 object[] objects = new object[2]; objects[0] = "Aisha"; object[1] = new Shape(); string str; for(int i=0; i&< objects.Length; i++) { str = objects as string; if(str == null) Console.WriteLine("can not be converted"); else Console.WriteLine("{0}",str); } 复制内容到剪贴板 代码: Output: Aisha can not be converted 语句 除了些许附加的新语句和修改外,C# 的语句和 C++ 的基本一致。 以下是新的语句: foreach 用于迭代数组等集合。 例子: 复制内容到剪贴板 代码: foreach (string s in array) Console.WriteLine(s); lock 在线程中使代码块称为重点部分。 (译注:lock 关键字将语句块标记为临界区,方法是获取给定对象的互斥锁,执行语句,然后释放该锁。lock 确保当一个线程位于代码的临界区时,另一个线程不进入临界区。如果其他线程试图进入锁定的代码,则它将一直等待(即被阻止),直到该对象被释放。) checked/unchecked 用于数字操作中的溢出检查。 例子: 复制内容到剪贴板 代码: int x = Int32.MaxValue; x++; // 溢出检查 { x++; // 异常 } unchecked { x++; // 溢出 } 下面的语句已修改:(译注:原文如此,疑为作者笔误) Switch Switch 语句在 C# 中修改过。 1.现在在执行一条 case 语句后,程序流不能跳至下一 case 语句。之前在 C++ 中这是可以的。 例子: 复制内容到剪贴板 代码: int var = 100; switch (var) { case 100: Console.WriteLine(""); // 这里没有 break case 200: Console.WriteLine(""); break; } C++ 的输出: 复制内容到剪贴板 代码: 而在 C# 中你将得到一个编译时错误: 复制内容到剪贴板 代码: error CS0163: Control cannot fall through from one case label ('case 100:') to another 2.然而你可以像在 C++ 中一样这么用: 复制内容到剪贴板 代码: switch (var) { case 100: case 200: Console.WriteLine("100 or 200"); break; } 3.你还可以用常数变量作为 case 值: 例子: 复制内容到剪贴板 代码: const string WeekEnd = "Sunday"; const string WeekDay1 = "Monday"; .... string WeekDay = Console.ReadLine(); switch (WeekDay ) { case WeekEnd: Console.WriteLine("It's weekend!!"); break; case WeekDay1: Console.WriteLine("It's Monday"); break; } 委托 委托让我们可以把函数引用保存在变量中。这就像在 C++ 中使用 typedef 保存函数指针一样。 委托使用关键字 delegate 声明。看看这个例子,你就能理解什么是委托: 例子: 复制内容到剪贴板 代码: delegate int Operation(int val1, int val2); public int Add(int val1, int val2) { return val1 + val2; } public int Subtract (int val1, int val2) { return val1- val2; } public void Perform() { Operation Oper; Console.WriteLine("Enter + or - "); string optor = Console.ReadLine(); Console.WriteLine("Enter 2 operands"); string opnd1 = Console.ReadLine(); string opnd2 = Console.ReadLine(); int val1 = Convert.ToInt32 (opnd1); int val2 = Convert.ToInt32 (opnd2); if (optor == "+") Oper = new Operation(Add); else Oper = new Operation(Subtract); Console.WriteLine(" Result = {0}", Oper(val1, val2)); } 继承与多态 C# 只允许单一继承。多重继承可以通过接口达到。 例子: 复制内容到剪贴板 代码: class Parent{ } class Child : Parent 虚函数 虚函数在 C# 中同样是用于实现多态的概念的,除了你要使用 override 关键字在子类中实现虚函数外。父类使用同样的 virtual 关键字。每个重写虚函数的类都使用 override 关键字。(译注:作者所说的“同样”,“除……外”都是针对 C# 和 C++ 而言的) 复制内容到剪贴板 代码: class Shape { public virtual void Draw() { Console.WriteLine("Shape.Draw") ; } } class Rectangle : Shape { public override void Draw() { Console.WriteLine("Rectangle.Draw"); } } class Square : Rectangle { public override void Draw() { Console.WriteLine("Square.Draw"); } } class MainClass { static void Main(string[] args) { Shape[] shp = new Shape[3]; Rectangle rect = new Rectangle(); shp[0] = new Shape(); shp[1] = rect; shp[2] = new Square(); shp[0].Draw(); shp[1].Draw(); shp[2].Draw(); } } Output: Shape.Draw Rectangle.Draw Square.Draw 使用“new”隐藏父类函数 你可以隐藏基类中的函数而在子类中定义其新版本。关键字 new 用于声明新的版本。思考下面的例子,该例是上一例子的修改版本。注意输出,我用 关键字 new 替换了 Rectangle 类中的关键字 override。 复制内容到剪贴板 代码: class Shape { public virtual void Draw() { Console.WriteLine("Shape.Draw") ; } } class Rectangle : Shape { public new void Draw() { Console.WriteLine("Rectangle.Draw"); } } class Square : Rectangle { //这里不用 override public new void Draw() { Console.WriteLine("Square.Draw"); } } class MainClass { static void Main(string[] args) { Console.WriteLine("Using Polymorphism:"); Shape[] shp = new Shape[3]; Rectangle rect = new Rectangle(); shp[0] = new Shape(); shp[1] = rect; shp[2] = new Square(); shp[0].Draw(); shp[1].Draw(); shp[2].Draw(); Console.WriteLine("Using without Polymorphism:"); rect.Draw(); Square sqr = new Square(); sqr.Draw(); } } Output: Using Polymorphism Shape.Draw Shape.Draw Shape.Draw Using without Polymorphism: Rectangle.Draw Square.Draw 多态性认为 Rectangle 类的 Draw 方法是和 Shape 类的 Draw 方法不同的另一个方法,而不是认为是其多态实现。所以为了防止父类和子类间的命名冲突,我们只有使用 new 修饰符。 注意:你不能在一个类中使用一个方法的两个版本,一个用 new 修饰符,另一个用 override 或 virtual。就像在上面的例子中,我不能在 Rectangle 类中增加另一个名为 Draw 的方法,因为它是一个 virtual 或 override 的方法。同样在 Square 类中,我也不能重写 Shape 类的虚方法 Draw。 调用基类成员 如果子类的数据成员和基类中的有同样的名字,为了避免命名冲突,基类成员和函数使用 base 关键字进行访问。看看下面的例子,基类构造函数是如何调用的,而数据成员又是如何使用的。 复制内容到剪贴板 代码: public Child(int val) :base(val) { myVar = 5; base.myVar; } OR public Child(int val) { base(val); myVar = 5 ; base.myVar; } 前景展望 本文仅仅是作为 C# 语言的一个快速浏览,以便你可以熟悉该语言的一些特性。尽管我尝试用实例以一种简短而全面的方式讨论了 C# 几乎所有的主要概念,但我认为还是有很多内容需要增加和讨论的。 以后,我会增加更多的没有讨论过的命令和概念,包括事件等。我还想给初学者写一下怎么用 C# 进行 Windows 编程。 参考文献: 我们都知道的 MSDN Tom Archer 著,Inside C# Eric Gunnerson 著,A Programmer's Introduction to C# Karli Watson 著,Beginning C# O'Reilly(奥莱利出版),Programming C# 修改: 2003年6月12日:按引用传递/输入-输出参数一节中增加了 ref 关键字 2003年6月20日:为可选参数增加了一条注意事项,纠正了交错数组例子中赋值运算符的笔误 许可 本文及其任何关联的源代码和文件均以 The Code Project Open License (CPOL)执行。(译注:代码计划网站公开许可)

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧