002 初识各类应用程序C#都能编写哪些程序

C#语言入门详解(002)——C#都能编写哪些程序.mp4 (147.83MB)

编程学习的捷径

学习原则

  • 从感官到原理
  • 从使用别人的到创建自己的
  • 必需亲自动手
  • 必需学以致用、紧跟实际工作
  • 追求实用,不搞“学院派”

初学编程时很重要的两点

  1. 不要怕见到自己不懂的东西
  2. 要能跟着操作,一遍一遍的练习,为的是熟悉手里的工具,培养感觉

见识 C# 编写的各类应用程序

基础概念补充:

solution 解决方案,是最高级别包含一个或多个project
project 解决具体的某个问题

各类应用程序实现HelloWorld

  • * 号的是推荐使用,2019主要应用为wpf(逐渐被.core替换),asp.net mvc,wcf

ConsoleHelloWorld.zip

  1. using System;
  2. namespace ConsoleHelloWorld
  3. {
  4. class Program
  5. {
  6. static void Main(string[] args)
  7. {
  8. Console.WriteLine("Hello World!");
  9. }
  10. }
  11. }
  • Windows Forms(Old)

WinFormHelloWorld.zip

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace WinFormHelloWorld
  11. {
  12. public partial class Form1 : Form
  13. {
  14. public Form1()
  15. {
  16. InitializeComponent();
  17. }
  18. private void ButtonSayHello_Click(object sender, EventArgs e)
  19. {
  20. TextBoxShowHello.Text = "Hello,World!";
  21. }
  22. }
  23. }
  • WPF(Windows Presentation Foundation)*

    WpfHelloWorld.zip ```csharp using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes;

namespace WpfHelloWorld { ///

/// MainWindow.xaml 的交互逻辑 /// public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); }

  1. private void ButtonSayHello_Click(object sender, RoutedEventArgs e)
  2. {
  3. TextBoxShowHello.Text = "Hello,World!";
  4. }
  5. }

}

  1. - ASP.NET Web Forms(Old)
  2. [WebFormHelloWorld.zip](https://www.yuque.com/attachments/yuque/0/2019/zip/446847/1571820440961-d6f3490a-595c-4c22-a146-19ee7e75f7c6.zip?_lake_card=%7B%22uid%22%3A%22rc-upload-1554455114339-10%22%2C%22src%22%3A%22https%3A%2F%2Fwww.yuque.com%2Fattachments%2Fyuque%2F0%2F2019%2Fzip%2F446847%2F1571820440961-d6f3490a-595c-4c22-a146-19ee7e75f7c6.zip%22%2C%22name%22%3A%22WebFormHelloWorld.zip%22%2C%22size%22%3A33135529%2C%22type%22%3A%22application%2Fx-zip-compressed%22%2C%22ext%22%3A%22zip%22%2C%22progress%22%3A%7B%22percent%22%3A0%7D%2C%22status%22%3A%22done%22%2C%22percent%22%3A0%2C%22id%22%3A%22CZccO%22%2C%22refSrc%22%3A%22https%3A%2F%2Fwww.yuque.com%2Fattachments%2Fyuque%2F0%2F2019%2Fzip%2F302433%2F1554455717211-5eb8899e-76fe-4de2-94c3-59775c74daa8.zip%22%2C%22card%22%3A%22file%22%7D)
  3. ```html
  4. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebFormHelloWorld.Default" %>
  5. <!DOCTYPE html>
  6. <html xmlns="http://www.w3.org/1999/xhtml">
  7. <head runat="server">
  8. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  9. <title></title>
  10. </head>
  11. <body>
  12. <h1>Hello,World!</h1>
  13. </body>
  14. </html>
  • ASP.NET MVC(Model-View-Controller)*

@{ ViewBag.Title = “Index”; }

Hello,World!

  1. - ~~Windows Store Application~~_(已被UWP替代,WIN10商店应用开发了解下即可)_
  2. - ~~Windows Phone Applicatio~~n_(已被UWP替代,且2019.1.9日微软已宣布放弃WP系统已可以无视)_
  3. - Cloud(Windos Azure)`*`
  4. [CloudHelloWorld.zip](https://www.yuque.com/attachments/yuque/0/2019/zip/446847/1571820441014-03744586-d68f-4a51-9667-eda3538a720a.zip?_lake_card=%7B%22uid%22%3A%22rc-upload-1554455114339-14%22%2C%22src%22%3A%22https%3A%2F%2Fwww.yuque.com%2Fattachments%2Fyuque%2F0%2F2019%2Fzip%2F446847%2F1571820441014-03744586-d68f-4a51-9667-eda3538a720a.zip%22%2C%22name%22%3A%22CloudHelloWorld.zip%22%2C%22size%22%3A112245819%2C%22type%22%3A%22application%2Fx-zip-compressed%22%2C%22ext%22%3A%22zip%22%2C%22progress%22%3A%7B%22percent%22%3A0%7D%2C%22status%22%3A%22done%22%2C%22percent%22%3A0%2C%22id%22%3A%22Y0eUf%22%2C%22refSrc%22%3A%22https%3A%2F%2Fwww.yuque.com%2Fattachments%2Fyuque%2F0%2F2019%2Fzip%2F302433%2F1554458251779-a0a2dd2d-0ef5-4838-a59c-5d669896243d.zip%22%2C%22card%22%3A%22file%22%7D)<br />代码同ASP.NET MVC 仅仅是发布形式不同
  5. - WF(Workflow Foundation)工作流/审判流开发_(很少应用)_
  6. - ![image.png](https://cdn.nlark.com/yuque/0/2019/png/302433/1554460295846-61de8280-874e-4b7b-b97c-735348ae9069.png#align=left&display=inline&height=343&name=image.png&originHeight=514&originWidth=945&size=19612&status=done&width=630)
  7. - WCF(Windows Communication Foundation)`*`
  8. WCF纯粹的网络服务,组件之间的通信<br />[WcfHelloWorld.zip](https://www.yuque.com/attachments/yuque/0/2019/zip/446847/1571820440957-be6a9c77-80e2-4b6d-884e-a1e3aa93861b.zip?_lake_card=%7B%22uid%22%3A%22rc-upload-1554458410787-4%22%2C%22src%22%3A%22https%3A%2F%2Fwww.yuque.com%2Fattachments%2Fyuque%2F0%2F2019%2Fzip%2F446847%2F1571820440957-be6a9c77-80e2-4b6d-884e-a1e3aa93861b.zip%22%2C%22name%22%3A%22WcfHelloWorld.zip%22%2C%22size%22%3A254244%2C%22type%22%3A%22application%2Fx-zip-compressed%22%2C%22ext%22%3A%22zip%22%2C%22progress%22%3A%7B%22percent%22%3A0%7D%2C%22status%22%3A%22done%22%2C%22percent%22%3A0%2C%22id%22%3A%22oEu9i%22%2C%22refSrc%22%3A%22https%3A%2F%2Fwww.yuque.com%2Fattachments%2Fyuque%2F0%2F2019%2Fzip%2F302433%2F1554459978824-83aac49e-7ac0-44b2-a790-44daef42b625.zip%22%2C%22card%22%3A%22file%22%7D)
  9. ```csharp
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Runtime.Serialization;
  14. using System.ServiceModel;
  15. using System.ServiceModel.Web;
  16. using System.Text;
  17. namespace WcfHelloWorld
  18. {
  19. // 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码、svc 和配置文件中的类名“Service1”。
  20. // 注意: 为了启动 WCF 测试客户端以测试此服务,请在解决方案资源管理器中选择 Service1.svc 或 Service1.svc.cs,然后开始调试。
  21. public class Service1 : IService1
  22. {
  23. public double Add(double a, double b)
  24. {
  25. return a+b;
  26. }
  27. public string GetData(int value)
  28. {
  29. return string.Format("You entered: {0}", value);
  30. }
  31. public CompositeType GetDataUsingDataContract(CompositeType composite)
  32. {
  33. if (composite == null)
  34. {
  35. throw new ArgumentNullException("composite");
  36. }
  37. if (composite.BoolValue)
  38. {
  39. composite.StringValue += "Suffix";
  40. }
  41. return composite;
  42. }
  43. public string SayHello()
  44. {
  45. return "Hello,World!";
  46. }
  47. }
  48. }

编程学习的捷径
学习原则

  • 从感官到原理
  • 从使用别人的到创建自己的
  • 必需亲自动手
  • 必需学以致用、紧跟实际工作
  • 追求实用,不搞“学院派”

见识 C# 编写的各类应用程序

* 号的是推荐使用。

  • Console
  • WPF(Windows Presentation Foundation)*
  • Windos Forms(Old)
  • ASP.NET Web Forms(Old)
  • ASP.NET MVC(Model-View-Controller)*
    • 分离不同种类的代码
    • 结构清晰,易于维护
  • WCF(Windows Communication Foundation)*
  • Windos Store Application*
  • Windows Phone Application*
  • Cloud(Windos Azure)*
  • WF(Workflow Foundation)