- Console
控制台:比如windows中的doc命令界面。
需要实现一个命令窗口中显示HelloWorld,如下要求
创建一个Console App(Application)项目,在Main函数中添加Console.WriteLine("Hello,World!");
,然后进行Debug中的Start Without Debugging进行运行,否则只会看到一闪而过的画面。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleHelloWord
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello,World!");
}
}
}
- Windows Forms (Old)
windows窗口程序
需要实现一个当点击Click Me按钮时,上方的TextBox控件中显示Hello,World!,如下
创建一个Windows Forms App项目,项目名 WinFormHelloWorld,在弹出来的Form中添加一个TextBox和Button控件,在双击Button按钮,进行Button按钮的函数,添加textBoxShowHello.text = "Hello,World!";
,注意这里的textBoxShowHello是TextBox属性中Design下的(Name)中的值。
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();
}
// button按钮所对应的函数,函数名是button中的(Name)属性值
private void buttonSayHello_Click(object sender, EventArgs e)
{
textBoxShowHello.Text = "Hello,World!";
}
}
}
- WPF (Windows Presentation Foundation)
WPF相对于Windows Form多出了XAML窗口
需要实现一个当点击Click Me按钮时,上方的TextBox控件中显示Hello,World!,如下
创建一个WPF App项目,项目名WpfHelloWorld
,为它修改背景颜色,添加TextBox和Button控件,修改控件的Name属性,并为Button添加点击函数,在函数中添加textBoxShowHello.text = "Hello,World!";
代码
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
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void buttonSayHello_Click(object sender, RoutedEventArgs e)
{
textBoxShowHello.Text = "Hello,World!";
}
}
}
- ASP.NET Web Forms (Old)
显示网络程序
需要在网页中实现一个Hello,World!
创建一个ASP.NET Web Application项目,后面选择Empty和web Forms,创建即可。
在创建好的项目上右键,点击Add->Web Form这时候就生成了一个以.aspx为后缀的文件(打开的话,里面内容跟html页面差不多,个人观点)。
在.aspx中添加<h1>Hello,World!</h1>
<%@ 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">
<title></title>
</head>
<body>
<h1>Hello,World!</h1>
</body>
</html>
点击IIS Express运行即可
- ASP.NET MVC (Model-View-Controller)
实现如下需求:
创建一个ASP.NET Web Application项目,后面选择Empty和MVC,创建即可。
在创建好的项目中找到controller文件夹,右键点击Add->Controller选择第一个,然后会进入Controller.cs页面里面函数如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MvcHelloWorld.Controllers
{
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
return View();
}
}
}
在Index()
函数右键点击Add View…选项,创建一个Index页面,修改其中的<h2></h2>
标签中的值改为Hello,World!,然后运行即可。
创建好的页面在Views\Home\文件夹下面。
@{
ViewBag.Title = "Index";
}
<h2>Hello,World!</h2>
点击IIS Express,运行。
-ASP.NET可以添加到网站中,右键项目然后选择pubish,具体操作,自行查找
- WCF (Windows Communication Foundation)
- Windows Store Application
平板电脑