- Beginning C# 7 Hands-On:Advanced Language Features
- Tom Owsiak
- 178字
- 2021-07-02 15:29:22
Chapter review
For review, the complete version of the Default.aspx.cs file for this chapter, including comments, is shown in the following code block:
//using is a directive
//System is a name space
//name space is a collection of features that our needs to run
using System;//needed for EventArgs
using System.Collections.Generic;//needed for dictionary
using System.Diagnostics;//needed for Process.Start
//public means accessible anywhere
//partial means this class is split over multiple files
//class is a keyword and think of it as the outermost level of grouping
//:System.Web.UI.Page means our page inherits the features of a Page
public partial class _Default : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
//make a dictionary using string as the type for keys and values
Dictionary<string, string> filePrograms =
new Dictionary<string, string>();
//add two key/value pairs to the dictionary
filePrograms.Add("notepad.exe", @"c:\data\samplefile.txt");
filePrograms.Add("iexplore.exe", "http://www.bing.com");
//iterate over the key/value pairs
foreach(KeyValuePair<string, string> kvp in filePrograms)
{
//invoke Process.Start to launch notepad and internet explorer
Process.Start(kvp.Key, kvp.Value);
}
//lines below get only at the key inside the filePrograms
//dictionary
foreach(string key in filePrograms.Keys)
{
sampLabel.Text += $"<br>{key}";
}
}
}
推薦閱讀
- SQL學習指南(第3版)
- MySQL數據庫應用與管理 第2版
- Vue.js前端開發基礎與項目實戰
- ASP.NET動態網頁設計教程(第三版)
- Linux網絡程序設計:基于龍芯平臺
- Kinect for Windows SDK Programming Guide
- SharePoint Development with the SharePoint Framework
- C語言開發基礎教程(Dev-C++)(第2版)
- SQL 經典實例
- Getting Started with Eclipse Juno
- 搞定J2EE:Struts+Spring+Hibernate整合詳解與典型案例
- Visual Basic程序設計習題與上機實踐
- OpenStack Networking Essentials
- Machine Learning for Developers
- 邊玩邊學Scratch3.0少兒趣味編程