63
William

DotNet Introduction

  • Upload
    wei-sun

  • View
    5.876

  • Download
    5

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: DotNet Introduction

William

Page 2: DotNet Introduction

Survey 听说过 DotNet, C# ( 1 )

知道什么是 C#, DotNet Framework ( 2 )

知道如何命令行编译 C# ( 1 )

编写过 C# 或者 VB.Net 程序 ( 2 )

知道什么是 CLR ( 2 )

知道什么是 Rails , ASP.NET MVC ( 2 )

知道什么是 Ruby, Python (1)

知道什么是 GC , LINQ ( 2 )

知道什么是 Functional Programming , Lambda ( 3 )

知道什么是 UI Automation MSTest MSBuild ( 2 )

知道什么是 Dynamic language in DotNet ( 2 )

Page 3: DotNet Introduction

What’s Framework?

http://en.wikipedia.org/wiki/Software_framework

Framework is an abstraction in which common code providing generic functionality can be selectively overridden or specialized by user code providing specific functionality. Frameworks are a special case of software libraries in that they are reusable abstractions of code wrapped in a well-defined API, yet they contain some key distinguishing features that separate them from normal libraries.

Frameworks have these distinguishing features that separate them from libraries or normal user applications: 1. inversion of control - In a framework, unlike in libraries or normal user applications, the overall program's flow of control is not dictated by the caller, but by the framework. 2. default behavior - A framework has a default behavior. This default behavior must actually be some useful behavior and not a series of no-ops. 3. extensibility - A framework can be extended by the user usually by selective overriding or specialized by user code providing specific functionality 4. non-modifiable framework code - The framework code, in general, is not allowed to be modified. Users can extend the framework, but not modify its code.

Page 4: DotNet Introduction

Quiz

Is DotNet framework a real framework? “Conversion over Configuration”?

Page 5: DotNet Introduction

http://msdn.microsoft.com/zh-cn/netframework/default.aspx

Page 6: DotNet Introduction

DotNet FAQ http://msdn.microsoft.com/en-us/library/ms973850.aspx

Page 7: DotNet Introduction

工具也是 .Net 的一部分? COM VisualStudio.Net Ado.Net Windows.Net

ASP.NET 囧 微软,你该找个起名大师了! Information , Service, Communication, Connection,

too many BIG concepts ! 新瓶装旧酒。 MVC 哪一年提出的概念? Garbage

Collection 哪一年? FP 哪一年?(参考 Wiki ) 从务虚到务实

Page 8: DotNet Introduction
Page 9: DotNet Introduction
Page 10: DotNet Introduction

http://java.sun.com/javase/6/docs/

Page 11: DotNet Introduction
Page 12: DotNet Introduction
Page 13: DotNet Introduction
Page 14: DotNet Introduction
Page 15: DotNet Introduction

Quiz

What is DotNet Framework? Why Microsoft design the DotNet? Why Microsoft didn’t use DotNet in OS? Why design C#? Why not C++?

Page 16: DotNet Introduction

下午 CSDN 记者参加了 Windows Phone 团队 Charles Kindle对开发平台的演讲。值得开发者注意的是, Windows Phone对第三方开放的开发框架就是两种:针对普通应用的Silverlight,针对游戏的 XNA,不再支持原生应用。

总而言之, Silverlight 就是 Windows Phone 7 Series 的应用开发平台(高性能游戏则可通过 XNA 框架进行开发),但 Windows Phone 7 Series 首先支持的不是最新的 Silverlight 4 ,而是 Silverlight 3 加上些手机特性的支持,比如位置服务、加速度传感器、推送提醒、手机电话等。

Page 17: DotNet Introduction
Page 18: DotNet Introduction

http://channel9.msdn.com/tags/

Page 19: DotNet Introduction

Quiz

Why we need to learn and use DotNet?

Page 20: DotNet Introduction

Why we need to use it? **** 1 New main tech in future, must learn it.

Windows Phone7, Windows7, etc.

2 Easy to use 3 New develop method (TDD) 4 Different view point, different design

idea

Page 21: DotNet Introduction

The common language runtime (CLR) is the execution engine for .NET Framework applications.

It provides a number of services, including the following: Code management (loading and execution) Application memory isolation Verification of type safety Conversion of IL to native code Access to metadata (enhanced type information) Managing memory for managed objects Enforcement of code access security Exception handling, including cross-language exceptions Interoperation between managed code, COM objects, and pre-

existing DLLs (unmanaged code and data) Automation of object layout Support for developer services (profiling, debugging, and so on)

Page 22: DotNet Introduction

MSDN .NET Framework

http://msdn.microsoft.com/en-us/library/system.io%28VS.100%29.aspx

http://en.wikipedia.org/wiki/.NET_Framework

http://zh.wikipedia.org/wiki/.NET%E6%A1%86%E6%9E%B6

http://msdn.microsoft.com/zh-cn/library/w0x726c2%28v=vs.90%29.aspx

Page 23: DotNet Introduction

.NET Framework Class Library

The .NET Framework class library is a library of classes, interfaces, and value types that provides access to system functionality and is designed to be the foundation on which .NET Framework applications, components, and controls are built.

Page 24: DotNet Introduction

The Base Class Library (BCL) includes a small subset of the entire class library and is the core set of classes that serve as the basic API of the Common Language Runtime.[9] The classes in mscorlib.dll and some of the classes in System.dll and System.core.dll are considered to be a part of the BCL. The BCL classes are available in both .NET Framework as well as its alternative implementations including .NET Compact Framework, Microsoft Silverlight and Mono.

The Framework Class Library (FCL) is a superset of the BCL classes and refers to the entire class library that ships with .NET Framework. It includes an expanded set of libraries, including WinForms, ADO.NET, ASP.NET, Language Integrated Query, WPF, WCF among others. The FCL is much larger in scope than standard libraries for languages like C++, and comparable in scope to the standard libraries of Java.

Page 25: DotNet Introduction

using System; using System.IO;namespace ConsoleApplication1{ class Program { public static long DirSize(DirectoryInfo d) { long Size = 0;

FileInfo[] fis = d.GetFiles(); foreach (FileInfo fi in fis) { Size += fi.Length; }

DirectoryInfo[] dis = d.GetDirectories(); foreach (DirectoryInfo di in dis) { Size += DirSize(di); } return (Size); }

static void Main(string[] args) { System.String dirName = "c:\\temp"; DirectoryInfo d = new DirectoryInfo(dirName); Console.WriteLine("The size of {0} and its subdirectories is {1} bytes.", d, DirSize(d)); } }}

Page 26: DotNet Introduction

import java.io.*;import java.util.*;public class DirUtils { public static List recurseDir(String dir) { String result, _result[]; result = RecurseDirFrom(dir); _result = result.split("\\|"); return Arrays.asList(_result); }

private static String RecurseDirFrom(String dirItem) { File file; String list[], result; result = dirItem; file = new File(dirItem); if (file.isDirectory()) { list = file.list(); for (int i = 0; i < list.length; i++) result = result + "|" + RecurseDirFrom(dirItem + File.separatorChar + list[i]); } return result; }

public static void main(String arg[]) { if (arg.length > 0) { System.out.println("recursive Dirs from " + arg[0]); System.out.println(DirUtils.recurseDir(arg[0])); } }}

Page 27: DotNet Introduction

Best practice

处理异常的最佳做法 开发全球通用应用程序的最佳做法 System.Net 类的最佳做法 托管线程处理的最佳做法

http://msdn.microsoft.com/zh-cn/library/ms184411%28v=vs.90%29.aspx

Page 28: DotNet Introduction

Examples 添加和移除内存压力应用程序示例 压缩应用程序示例 字数统计应用程序示例 .NET 客户端 Stopwatch 应用程序示例 CLR 版本检测技术示例 组件服务示例 垃圾回收技术示例 COM 互操作性示例 本地化示例 网络连接示例 反射示例 远程处理示例 序列化示例 线程示例 值和枚举类型技术示例 Windows 窗体控件示例

Page 29: DotNet Introduction

VB.net vs C#.net

Complete Comparison for VB.NET and C# Google “vb c# translate” http://support.microsoft.com/kb/308470 http://www.harding.edu/fmccown/vbnet_csharp_co

mparison.html

Page 30: DotNet Introduction

C# Programming Tools

http://msdn.microsoft.com/zh-cn/vcsharp/default.aspx CSharp Development Center

http://msdn.microsoft.com/en-us/magazine/cc300497.aspx Ten Must-Have Tools Every Developer Should Download

http://www.codeplex.com

Page 31: DotNet Introduction
Page 32: DotNet Introduction

http://www.microsoft.com/china/msdn/events/webcasts/shared/Webcast/MSDNWebCast.aspx

Use iReaper to download

Page 33: DotNet Introduction
Page 34: DotNet Introduction

http://channel9.msdn.com/tags/CSharp/

Page 35: DotNet Introduction

http://msdn.microsoft.com/zh-cn/practices/default.aspx

Page 36: DotNet Introduction

http://code.msdn.microsoft.com/Project/ProjectDirectory.aspx?TagName=C%23

Page 37: DotNet Introduction

DotNet internal http://mono-project.com/ http://blogs.msdn.com/sburke/archive/2008/01/16/configuring-visual-stu

dio-to-debug-net-framework-source-code.aspx http://netmassdownloader.codeplex.com Shared Source Common Language Infrastructure 2.0 Release

Page 38: DotNet Introduction

Copy and Clone

DotNet Platform copy Java Platform

WCF(Odata) copy XMLRPC

WPF copy RIA (Flash, Flex, Html5, JavaFx)

C# language copy Java language

Azure copy Amazon S3 (Google cp it too)

Team system copy 持续集成

Win7 copy MacOSX

Page 39: DotNet Introduction
Page 40: DotNet Introduction

Why we say “platform”

Dynamic languageIronPython, IronRuby, Lua

Functional ProgrammingFsharp

You need to know moreJavaScript ( www.jquery.com ) for asp.netWeb development, html, cssFront dev, server-side dev, do we need

desktop?

Page 41: DotNet Introduction

IronPython Demo

Used in: Desktop application, small utility. http://www.ironpython.info/index.php/Contents#Windows_Forms

Page 42: DotNet Introduction

# http://www.ironpython.info/index.php/Interacting_with_Excel

# ref: Excel 2003 VBA Language Referenceimport clr

from System import Array

from System import DateTime

clr.AddReference("Microsoft.Office.Interop.Excel")

import Microsoft.Office.Interop.Excel as Excel

excel = Excel.ApplicationClass()

excel.Visible = True

workbook = excel.Workbooks.Add()

worksheet = workbook.Worksheets.Add()

worksheet.Name = "aaaaa"

cell1 = worksheet.Range["A2"]

cell1.Value2 = 42

xlrange = worksheet.Range["A3", "b4“]

arr1 = Array.CreateInstance(object, 2, 2)

arr1[0, 0] = DateTime.Now

arr1[0, 1] = 3

arr1[1, 0] = "hi Excel test."

arr1[1, 1] = "hi there!"

xlrange.Value2 = arr1

Page 43: DotNet Introduction

IronRuby Demo Used in: Quick dirty website. Sinatra, Rails ir, igem,

Page 44: DotNet Introduction

require 'rubygems'

require 'sinatra'

get '/hi' do

"Hello World!“

end

get '/hi/:name' do

# matches "GET /hello/foo" and "GET /hello/bar"

# params[:name] is 'foo' or 'bar'

"Hello #{params[:name]}! you come from /hi"

end

Page 45: DotNet Introduction

Quiz

Why we should learn and use dynamic language?

Which area is suitable for Ruby/Python?

Page 46: DotNet Introduction

Survey

First gets 3, second gets 1, third gets 0, how about your rate?

Web develop, DotNet(C#) vs Ruby/Python vs Java

Desktop develop, DotNet(C#) vs Ruby/Python vs Java

Cross OperationSystem, DotNet(C#) vs Ruby/Python vs Java

Embedded (Phone), DotNet(C#) vs Ruby/Python vs Java

Game (Server) develop, DotNet(C#) vs Ruby/Python vs Java

Page 47: DotNet Introduction

A New World – F#Csharp:

int[] numbers = new int[7] { 0, 1, 2, 3, 4, 5, 6 };

var numQuery = from num in numbers

where (num % 2) == 0

select num;

foreach (int num in numQuery)

{

Console.Write("{0,1} ", num);

}

Fsharp:

let listN = List.filter (fun n -> (n % 2) = 0) [0..6];;

printfn "listN = %A" listN

http://msdn.microsoft.com/en-us/fsharp/default.aspx

Page 48: DotNet Introduction

let rec qsort L =

match L with

| [] -> []

| x::xs ->

let smaller = [for i in xs when i <= x -> i] in

let larger = [for i in xs when i > x -> i] in

qsort smaller @ [x] @ qsort larger;;

qsort [3;5;1;4;2];;

qsort [7;5;10;2;3;67;1;3];;

qsort ["Hello"; "AA"; "hello"; "help"; "Aa"; "aa";];;

http://www.gofsharp.com/FS/Translations/Hutton/Hutton.txt

Page 49: DotNet Introduction

Fsharp Demo

http://research.microsoft.com/en-us/people/dsyme/ http://www.cnblogs.com/JeffreyZhao/tag/F%23/

*** Fsharp could do all work that Csharp could ***

Page 50: DotNet Introduction

Quiz

Why we should learn/use Functional language?

Which area is suitable for Fsharp? Concurrency? Parallelism?

Page 51: DotNet Introduction

Concurrency (Erlang) and parallelism (Fsharp)are NOT the same thing. Two tasks T1 and T2 are concurrent if the order in which the two tasks are executed in time is not predetermined, T1 may be executed and finished before T2, T2 may be executed and finished before T1, T1 and T2 may be executed simultaneously at the same instance of time

(parallelism), T1 and T2 may be executed alternatively,

If two concurrent threads are scheduled by the OS to run on one single-core non-SMT non-CMP processor, you may get concurrency but not parallelism. Parallelism is possible on multi-core, multi-processor or distributed systems.

Concurrency is often referred to as a property of a program, and is a concept more general than parallelism.

Page 52: DotNet Introduction

SliverLight more important UIAutomation Test Odata Azure platform ASP.net MVC MVVM

Page 53: DotNet Introduction
Page 54: DotNet Introduction

Advance topic : Garbage Collection Garbage Collection useful documents

http://www.ibm.com/developerworks/cn/java/j-jtp10283/ http://www.ibm.com/developerworks/cn/java/l-JavaMemoryLeak2/index.html http://blogs.msdn.com/maoni/archive/2004/06/15/156626.aspx http://msdn.microsoft.com/zh-cn/library/0xy59wtx.aspx http://blogs.msdn.com/maoni/archive/2004/06/15/156626.aspx http://blogs.msdn.com/maoni/archive/2004/09/25/234273.aspx http://blogs.msdn.com/maoni/archive/2004/12/19/327149.aspx http://blogs.msdn.com/maoni/archive/2005/05/06/415296.aspx http://www.codeproject.com/KB/dotnet/garbagecollection.aspx http://blogs.msdn.com/tess/archive/2006/09/06/net-memory-usage-a-restaurant-analo

gy.aspx http://msdn.microsoft.com/en-us/library/ms973837.aspx http://msdn.microsoft.com/en-us/library/f144e03t.aspx

Page 55: DotNet Introduction

Quiz

How to design a garbage collection library?

Page 56: DotNet Introduction

In DotNet, managed heap concept.http://www.codeguru.com/columns/dotnet/article.php/c6593

Page 57: DotNet Introduction

GC 常用技术 引用计数

COM , smart pointer Tracing

Mark-Compact 此算法結合了“標記 - 清除”和“複製”兩個演算法的優點。也是分兩階段,第一 階段從根節點開始標記所有被引用物件,第二階段遍歷整個 heap ,把清除未標記物件並且把存活物件“壓縮”到 heap 的其中一塊,按順序排放。此演算法避免了“標記 - 清除”的碎片問題,同時也避免了“複製”算法的空間問題。

http://pt.withy.org/publications/AMM.pdfhttp://www.cs.nctu.edu.tw/~kjji/GC.pptxhttp://moon.nju.edu.cn/twiki/pub/ICSatNJU/CourseOOT/04_Memory_Management.ppt

http://www.cs.wustl.edu/~mdeters/doc/slides/rtgc-history.pdf

http://lua-users.org/wiki/GarbageCollectionTutorial

http://blog.csdn.net/akara/archive/2010/03/23/5408678.aspx

http://en.wikipedia.org/wiki/Garbage_collection_%28computer_science%29

Page 58: DotNet Introduction

http://chaoticjava.com/posts/how-does-garbage-collection-work/

Page 59: DotNet Introduction

Advance topic Add-ins and ExtensibilityDescribes how to develop add-in applications that extend a host application's functionality. Asynchronous Programming Design PatternsDescribes two design patterns available in the .NET Framework that are

used to run threads separately from the main application thread. Component Authoring for the Design EnvironmentProvides links to information about creating your own components in

the .NET Framework, customizing their behavior and display, and creating custom controls for the Windows Presentation Foundation (WPF).

Dynamic Source Code Generation and CompilationDiscusses the Code Document Object Model (CodeDOM), which enables the output of source code in multiple programming languages.

Emitting Dynamic Methods and AssembliesDescribes a set of managed types in the System.Reflection.Emit namespace that enable a compiler or tool to emit metadata and Microsoft intermediate language (MSIL) at run time and optionally generate a portable executable (PE) file on disk.

Expression TreesIntroduces expression trees, which are tree-shaped data structures that can be used to represent language-level code in the form of data.

Garbage CollectionDiscusses how the garbage collector manages memory and how you can program to use memory more efficiently.

Hosting the Common Language RuntimeExplains the concept of a runtime host, which loads the runtime into a process, creates the application domain in the process, and loads and executes user code.

InteroperabilityDescribes services provided by the .NET Framework for interaction with COM components, COM+ services, external type libraries, and many operating system services.

.NET RemotingDiscusses establishing communication between objects that run in different processes. Network ProgrammingShows how to use Internet access classes to implement both Web- and Internet-based

applications. ReflectionExplains how to obtain access to type information at run time by using reflection. ReliabilityDiscusses writing reliable code for any host that is executing in a .NET Framework environment. SerializationDiscusses the process of converting the state of an object into a form that can be persisted or transported. Managed ThreadingExplains the runtime support for threading and how to program by using various synchronization

techniques. Writing Serviced ComponentsDescribes how to configure and register serviced components to access COM+ services.

Page 60: DotNet Introduction

More questions?

MSDN Codeproject.com StackOverflow.com Codeplex.com Wiki Blog search MSDN forum http://www.cnblogs.com

Page 61: DotNet Introduction

DotNet shortcoming

YAGNI, too big, too over. 新名词, Oh No ! ORZ ! 技术依赖强烈 Silverlight + WCF 平台及工具 IDE 依赖强烈 学习曲线陡峭 变化剧烈 WinForm or WPF? Remoting or WCF? 大而全?还是大而无当?

Page 62: DotNet Introduction

重点学习” stable” and “Internal” knowledge ,新技术不过是它们的组合包装 . RPC, XML, HTTP, Socket, GC, Dynamic language, FP, UnitTest, CLR, API design, Framework design, String code, RE, DataStructure, Algorithm, Web framework pattern

适当了解你需要的 DotNet Framework, WCF, WPF, Asp.net, Silverlight

保持对技术的好奇心

使用新版本 , Win7 + DotNet4 + VS2010

Page 63: DotNet Introduction

Learn it, Use it, Share it!