官术网_书友最值得收藏!

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}";
}
}
}
主站蜘蛛池模板: 大渡口区| 咸丰县| 临沧市| 江口县| 盱眙县| 正安县| 德钦县| 洛川县| 林芝县| 保山市| 和田市| 荃湾区| 大连市| 卢湾区| 枣强县| 喀喇| 麦盖提县| 昂仁县| 平塘县| 莲花县| 旬邑县| 绩溪县| 岫岩| 雷州市| 临漳县| 巴东县| 芦溪县| 铜梁县| 北宁市| 林芝县| 高邮市| 洞口县| 乐东| 曲沃县| 广饶县| 宜城市| 洱源县| 和林格尔县| 陆丰市| 楚雄市| 临漳县|