002 初识各类应用程序C#都能编写哪些程序
编程学习的捷径
学习原则
- 从感官到原理
- 从使用别人的到创建自己的
- 必需亲自动手
- 必需学以致用、紧跟实际工作
- 追求实用,不搞“学院派”
初学编程时很重要的两点
- 不要怕见到自己不懂的东西
- 要能跟着操作,一遍一遍的练习,为的是熟悉手里的工具,培养感觉
见识 C# 编写的各类应用程序
基础概念补充:
solution | 解决方案,是最高级别包含一个或多个project |
---|---|
project | 解决具体的某个问题 |
各类应用程序实现HelloWorld
- 带
*
号的是推荐使用,2019主要应用为wpf(逐渐被.core替换),asp.net mvc,wcf
using System;
namespace ConsoleHelloWorld
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
- Windows Forms(Old)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WinFormHelloWorld
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void ButtonSayHello_Click(object sender, EventArgs e)
{
TextBoxShowHello.Text = "Hello,World!";
}
}
}
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 { ///
private void ButtonSayHello_Click(object sender, RoutedEventArgs e)
{
TextBoxShowHello.Text = "Hello,World!";
}
}
}
- ASP.NET Web Forms(Old)
[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)
```html
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebFormHelloWorld.Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<h1>Hello,World!</h1>
</body>
</html>
- ASP.NET MVC(Model-View-Controller)
*
- 分离不同种类的代码
- 结构清晰,易于维护
- MvcHelloWorld.zip ```html
@{ ViewBag.Title = “Index”; }
Hello,World!
- ~~Windows Store Application~~_(已被UWP替代,WIN10商店应用开发了解下即可)_
- ~~Windows Phone Applicatio~~n_(已被UWP替代,且2019.1.9日微软已宣布放弃WP系统已可以无视)_
- Cloud(Windos Azure)`*`
[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 仅仅是发布形式不同
- WF(Workflow Foundation)工作流/审判流开发_(很少应用)_
- ![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)
- WCF(Windows Communication Foundation)`*`
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)
```csharp
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace WcfHelloWorld
{
// 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码、svc 和配置文件中的类名“Service1”。
// 注意: 为了启动 WCF 测试客户端以测试此服务,请在解决方案资源管理器中选择 Service1.svc 或 Service1.svc.cs,然后开始调试。
public class Service1 : IService1
{
public double Add(double a, double b)
{
return a+b;
}
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
public CompositeType GetDataUsingDataContract(CompositeType composite)
{
if (composite == null)
{
throw new ArgumentNullException("composite");
}
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
public string SayHello()
{
return "Hello,World!";
}
}
}
编程学习的捷径
学习原则
- 从感官到原理
- 从使用别人的到创建自己的
- 必需亲自动手
- 必需学以致用、紧跟实际工作
- 追求实用,不搞“学院派”
见识 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)