C#常见的应用程序类型
- 控制台应用程序
- Windows应用程序(WPF程序)
- Web应用程序(Mobile应用程序)
注: Web应用程序(网上)
Mobile应用程序(手机上)
一、.控制台应用程序
(运行快捷键Ctrl+F5)
using 名称空间
例:using System
使用System名称空间,以便编程的简写,方便书写。
如:System.Console.Writeline("Hello Singto");
如果将引用using System;时,
可以简写为:Console.Writeline("Hello Singto");
namespace 名称空间
例:namespace contoral
目的:使该空间(contoral)中的类和其他空间中的类不重名。
如:System.Threading.task;
程序中的Main()函数:static void Main(String[] args)
注:
类定义:
calss 类名
例:class dog{ }
程序中的重要组成部分是类(class),所有的内容都要放进类(class)里面.
Main()方法:
程序入口是Main()方法。它有固定的书写格式。
- public static void Main(string[] args)
- 可以没有publi,可以没有string[] args
Main()方法的简单编写方式:
svm+按两次Tab键。
svm=static viod Main()
例:
代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contoral
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello Singto!");//由控制台输出显示
}
}
}
二、Windows应用程序(WinForm应用)
VS.NET设计程序
- 可视化的设计窗体
- 事件驱动的编程机制
如上一篇笔记C#入门
注意:
-
using System.Windows.Forms;
使用(导入) -
namespace xxxxx{…}
命名空间 -
public class Form1:System.Windows.Forms.Form
继承(面向对象的重要内容) -
自动生成的代码
对象的生成(new)
例:Random rnd = new Random();
事件的注册(+=)
例:this.buttton1.click += new System.EventHandler(this.button1_click);
三、Web应用程序
- 在.NET中也称ASP.NET(活动的服务器网页)应用程序
- 应用程序在服务器上运行,客户端使用浏览器(如IE)来进行输入输出
- 这种方式称为B/S(Browser/Server)方式
与传统C/S(Client/Server)相区别
B/S应用程序在使用上、部署上有独特的优势
创建Web应用程序:
创建->文件->项目->Web->Visual Studio->ASP.NET空Web应用程序->添加Web窗体->书写html代码或点击设计
ToUpper();转化为大写
protected void Button1_Click(object sender, EventArgs e)
{
this.Label1.Text = this.TextBox1.Text.ToUpper();//将输入文本框的内容转化成大写输出。
}
拓:
解析实数,可以用double的什么方法:
double.Parse()或double.parse或Parse()或Parse
求平方根,可以用哪个函数:
Math.Sqrt()或Math.Sqrt或Sqrt或Sqrt()
@梦幻泡沫
来源:CSDN
作者:Mr_Singto
链接:https://blog.csdn.net/Mr_Singto/article/details/104172938