- 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}";
}
}
}
推薦閱讀
- TypeScript入門與實(shí)戰(zhàn)
- Android項(xiàng)目開發(fā)入門教程
- 移動(dòng)UI設(shè)計(jì)(微課版)
- LabVIEW入門與實(shí)戰(zhàn)開發(fā)100例
- MySQL 8 DBA基礎(chǔ)教程
- 數(shù)據(jù)結(jié)構(gòu)(Python語言描述)(第2版)
- 精通Python自然語言處理
- Visual C++數(shù)字圖像處理技術(shù)詳解
- FLL+WRO樂高機(jī)器人競(jìng)賽教程:機(jī)械、巡線與PID
- C++ Application Development with Code:Blocks
- Bootstrap for Rails
- OpenCV with Python Blueprints
- Java EE Web應(yīng)用開發(fā)基礎(chǔ)
- PHP+MySQL動(dòng)態(tài)網(wǎng)站開發(fā)從入門到精通(視頻教學(xué)版)
- Mastering OpenStack