Skip to content

Commit 5d52114

Browse files
committed
summarizing examples ExamRef70-483#6
1 parent 893af7f commit 5d52114

File tree

80 files changed

+284
-285
lines changed
  • LISTING 4-10 The DirectoryInfo class/LISTING 4-10 The DirectoryInfo class
  • LISTING 4-11 Using Path/LISTING 4-11 Using Path
  • LISTING 4-12 C sharp programs/LISTING 4-12 C sharp programs
  • LISTING 4-13 httpWebRequest/LISTING 4-13 httpWebRequest
  • LISTING 4-14 TCP over sockets/LISTING 4-14 TCP over sockets
  • LISTING 4-15 PageViewer/LISTING 4-15 PageViewer
  • LISTING 4-15 WebClient async/LISTING 4-15 WebClient async
  • LISTING 4-16 HttpClient/LISTING 4-16 HttpClient
  • LISTING 4-17 Asynchronous file writing/LISTING 4-17 Asynchronous file writing
  • LISTING 4-18 File exceptions/LISTING 4-18 File exceptions
  • LISTING 4-19 Read with SQL/LISTING 4-19 Read with SQL
  • LISTING 4-1 Using a FileStream/LISTING 4-1 Using a FileStream
  • LISTING 4-20 Filter with SQL/LISTING 4-20 Filter with SQL
  • LISTING 4-21 Update with SQL/LISTING 4-21 Update with SQL
  • LISTING 4-22 SQL injection/LISTING 4-22 SQL injection
  • LISTING 4-23 Parameterized query/LISTING 4-23 Parameterized query
  • LISTING 4-24 Asynchronous access/LISTING 4-24 Asynchronous access
  • LISTING 4-25 NASA JSON/LISTING 4-25 NASA JSON
  • LISTING 4-26 XML elements/LISTING 4-26 XML elements
  • LISTING 4-27 XML DOM/LISTING 4-27 XML DOM
  • LISTING 4-28 Web Service
  • LISTING 4-29 Musictrack classes/LISTING 4-29 Musictrack classes
  • LISTING 4-2 FileStream and IDisposable/LISTING 4-2 FileStream and IDisposable
  • LISTING 4-30 LINQ operators/LISTING 4-30 LINQ operators
  • LISTING 4-31 var errors/LISTING 4-31 var errors
  • LISTING 4-32 var and LINQ/LISTING 4-32 var and LINQ
  • LISTING 4-33 LINQ projection/LISTING 4-33 LINQ projection
  • LISTING 4-34 Anonymous type/LISTING 4-34 Anonymous type
  • LISTING 4-35 LINQ join/LISTING 4-35 LINQ join
  • LISTING 4-36 LINQ group/LISTING 4-36 LINQ group
  • LISTING 4-38 LINQ aggregate/LISTING 4-38 LINQ aggregate
  • LISTING 4-39 Method based query/LISTING 4-39 Method based query
  • LISTING 4-3 StreamWriter and StreamReader/LISTING 4-3 StreamWriter and StreamReader
  • LISTING 4-40 Complex query/LISTING 4-40 Complex query
  • LISTING 4-41 Complex anonymous types/LISTING 4-41 Complex anonymous types
  • LISTING 4-42 Force query execution/LISTING 4-42 Force query execution
  • LISTING 4-43 Read XML with LINQ/LISTING 4-43 Read XML with LINQ
  • LISTING 4-44 Filter XML with LINQ/LISTING 4-44 Filter XML with LINQ
  • LISTING 4-45 Create XML with LINQ/LISTING 4-45 Create XML with LINQ
  • LISTING 4-46 Modify XML with LINQ/LISTING 4-46 Modify XML with LINQ
  • LISTING 4-47 Add XML with LINQ/LISTING 4-47 Add XML with LINQ
  • LISTING 4-48 Binary serialization/LISTING 4-48 Binary serialization
  • LISTING 4-49 Custom serialization/LISTING 4-49 Custom serialization
  • LISTING 4-4 Storing compressed files/LISTING 4-4 Storing compressed files
  • LISTING 4-50 Customization methods/LISTING 4-50 Customization methods
  • LISTING 4-51 Binary versions/LISTING 4-51 Binary versions
  • LISTING 4-52 XML Serialization/LISTING 4-52 XML Serialization
  • LISTING 4-53 XML References/LISTING 4-53 XML References
  • LISTING 4-54 Data contract serializer/LISTING 4-54 Data contract serializer
  • LISTING 4-55 Array example/LISTING 4-55 Array example
  • LISTING 4-56 ArrayList example/LISTING 4-56 ArrayList example
  • LISTING 4-57 List example/LISTING 4-57 List example
  • LISTING 4-58 Dictionary example/LISTING 4-58 Dictionary example
  • LISTING 4-59 Word counter/LISTING 4-59 Word counter
  • LISTING 4-5 The File class/LISTING 4-5 The File class
  • LISTING 4-60 Set example/LISTING 4-60 Set example
  • LISTING 4-61 Queue example/LISTING 4-61 Queue example
  • LISTING 4-62 Stack example/LISTING 4-62 Stack example
  • LISTING 4-63 Collection initialization/LISTING 4-63 Collection initialization
  • LISTING 4-64 Grow an array/LISTING 4-64 Grow an array
  • LISTING 4-65 List modification/LISTING 4-65 List modification
  • LISTING 4-66 Dictionary modification/LISTING 4-66 Dictionary modification
  • LISTING 4-67 Set modification/LISTING 4-67 Set modification
  • LISTING 4-68 Custom collection/LISTING 4-68 Custom collection
  • LISTING 4-69 ICollection interface/LISTING 4-69 ICollection interface
  • LISTING 4-6 Stream exceptions/LISTING 4-6 Stream exceptions
  • LISTING 4-7 Drive information/LISTING 4-7 Drive information
  • LISTING 4-8 Using FileInfo/LISTING 4-8 Using FileInfo
  • LISTING 4-8 Viewing FileInfo/LISTING 4-8 Viewing FileInfo
  • LISTING 4-9 The Directory class/LISTING 4-9 The Directory class

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+284
-285
lines changed

LISTING 4-10 The DirectoryInfo class/LISTING 4-10 The DirectoryInfo class/Program.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.IO;
33

4-
54
namespace LISTING_4_10_The_DirectoryInfo_class
65
{
76
class Program
@@ -22,4 +21,4 @@ static void Main(string[] args)
2221
Console.ReadKey();
2322
}
2423
}
25-
}
24+
}

LISTING 4-11 Using Path/LISTING 4-11 Using Path/Program.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ class Program
77
{
88
static void Main(string[] args)
99
{
10-
1110
string fullName = @"c:\users\rob\Documents\test.txt";
1211

1312
string dirName = Path.GetDirectoryName(fullName);
@@ -24,7 +23,6 @@ static void Main(string[] args)
2423
Console.WriteLine("New test: {0}", newTest);
2524

2625
Console.ReadKey();
27-
2826
}
2927
}
30-
}
28+
}

LISTING 4-12 C sharp programs/LISTING 4-12 C sharp programs/Program.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ static void Main(string[] args)
2828
Console.ReadKey();
2929
}
3030
}
31-
}
31+
}

LISTING 4-13 httpWebRequest/LISTING 4-13 httpWebRequest/Program.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ static void Main(string[] args)
2020
Console.ReadKey();
2121
}
2222
}
23-
}
23+
}

LISTING 4-14 TCP over sockets/LISTING 4-14 TCP over sockets/Program.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ private static string ReceiveMessageTCP(out string message)
176176
return response;
177177
}
178178

179-
180179
/// <summary>
181180
/// Closes an open connection
182181
/// </summary>
@@ -257,4 +256,4 @@ static void Main(string[] args)
257256
WebRequest x = WebRequest.Create("url");
258257
}
259258
}
260-
}
259+
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Configuration;
4-
using System.Data;
5-
using System.Linq;
6-
using System.Threading.Tasks;
7-
using System.Windows;
1+
using System.Windows;
82

93
namespace PageViewer
104
{
@@ -14,4 +8,4 @@ namespace PageViewer
148
public partial class App : Application
159
{
1610
}
17-
}
11+
}

LISTING 4-15 PageViewer/LISTING 4-15 PageViewer/MainWindow.xaml.cs

+2-14
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Net;
5-
using System.Text;
1+
using System.Net;
62
using System.Threading.Tasks;
73
using System.Windows;
8-
using System.Windows.Controls;
9-
using System.Windows.Data;
10-
using System.Windows.Documents;
11-
using System.Windows.Input;
12-
using System.Windows.Media;
13-
using System.Windows.Media.Imaging;
14-
using System.Windows.Navigation;
15-
using System.Windows.Shapes;
164

175
namespace PageViewer
186
{
@@ -39,4 +27,4 @@ private async void StartButton_Click(object sender, RoutedEventArgs e)
3927
ResultTextBlock.Text = webText;
4028
}
4129
}
42-
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
1+
using System.Net;
52
using System.Threading.Tasks;
63

74
namespace LISTING_4_15_WebClient_async
85
{
96
class Program
107
{
8+
static async Task<string> readWebpage(string uri)
9+
{
10+
WebClient client = new WebClient();
11+
return await client.DownloadStringTaskAsync(uri);
12+
}
13+
1114
static void Main(string[] args)
1215
{
16+
readWebpage("http://www.microsoft.com");
1317
}
1418
}
15-
}
19+
}

LISTING 4-16 HttpClient/LISTING 4-16 HttpClient/App.xaml.cs

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.IO;
4-
using System.Linq;
5-
using System.Runtime.InteropServices.WindowsRuntime;
62
using Windows.ApplicationModel;
73
using Windows.ApplicationModel.Activation;
8-
using Windows.Foundation;
9-
using Windows.Foundation.Collections;
104
using Windows.UI.Xaml;
115
using Windows.UI.Xaml.Controls;
12-
using Windows.UI.Xaml.Controls.Primitives;
13-
using Windows.UI.Xaml.Data;
14-
using Windows.UI.Xaml.Input;
15-
using Windows.UI.Xaml.Media;
166
using Windows.UI.Xaml.Navigation;
177

188
namespace PageViewer
@@ -97,4 +87,4 @@ private void OnSuspending(object sender, SuspendingEventArgs e)
9787
deferral.Complete();
9888
}
9989
}
100-
}
90+
}

LISTING 4-16 HttpClient/LISTING 4-16 HttpClient/MainPage.xaml.cs

+1-13
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,9 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.IO;
4-
using System.Linq;
52
using System.Net.Http;
6-
using System.Runtime.InteropServices.WindowsRuntime;
73
using System.Threading.Tasks;
8-
using Windows.Foundation;
9-
using Windows.Foundation.Collections;
104
using Windows.UI.Popups;
115
using Windows.UI.Xaml;
126
using Windows.UI.Xaml.Controls;
13-
using Windows.UI.Xaml.Controls.Primitives;
14-
using Windows.UI.Xaml.Data;
15-
using Windows.UI.Xaml.Input;
16-
using Windows.UI.Xaml.Media;
17-
using Windows.UI.Xaml.Navigation;
187

198
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
209

@@ -36,7 +25,6 @@ async Task<string> readWebpage(string uri)
3625
return await client.GetStringAsync(uri);
3726
}
3827

39-
4028
private async void StartButton_Click(object sender, RoutedEventArgs e)
4129
{
4230
try
@@ -51,4 +39,4 @@ private async void StartButton_Click(object sender, RoutedEventArgs e)
5139
}
5240
}
5341
}
54-
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Configuration;
4-
using System.Data;
5-
using System.Linq;
6-
using System.Threading.Tasks;
7-
using System.Windows;
1+
using System.Windows;
82

93
namespace FileWriter
104
{
@@ -14,4 +8,4 @@ namespace FileWriter
148
public partial class App : Application
159
{
1610
}
17-
}
11+
}

LISTING 4-17 Asynchronous file writing/LISTING 4-17 Asynchronous file writing/MainWindow.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,4 @@ private void TimeButton_Click(object sender, RoutedEventArgs e)
6060
TimeTextBlock.Text = DateTime.Now.ToLongTimeString();
6161
}
6262
}
63-
}
63+
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Configuration;
4-
using System.Data;
5-
using System.Linq;
6-
using System.Threading.Tasks;
7-
using System.Windows;
1+
using System.Windows;
82

93
namespace FileWriter
104
{
@@ -14,4 +8,4 @@ namespace FileWriter
148
public partial class App : Application
159
{
1610
}
17-
}
11+
}

LISTING 4-18 File exceptions/LISTING 4-18 File exceptions/MainWindow.xaml.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,5 @@ private void StartVoidButton_Click(object sender, RoutedEventArgs e)
6060
MessageBox.Show(writeException.Message, "File write failed");
6161
}
6262
}
63-
6463
}
65-
}
64+
}

LISTING 4-19 Read with SQL/LISTING 4-19 Read with SQL/Program.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,5 @@ static void Main(string[] args)
3131

3232
Console.ReadKey();
3333
}
34-
3534
}
36-
}
35+
}

LISTING 4-1 Using a FileStream/LISTING 4-1 Using a FileStream/Program.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ static void Main(string[] args)
2525
Console.ReadKey();
2626
}
2727
}
28-
}
28+
}

LISTING 4-20 Filter with SQL/LISTING 4-20 Filter with SQL/Program.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ static void Main(string[] args)
3131
Console.ReadKey();
3232
}
3333
}
34-
}
34+
}

LISTING 4-21 Update with SQL/LISTING 4-21 Update with SQL/Program.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Data.SqlClient;
33

4-
54
namespace LISTING_4_21_Update_with_SQL
65
{
76
class Program
@@ -47,4 +46,4 @@ static void Main(string[] args)
4746
Console.ReadKey();
4847
}
4948
}
50-
}
49+
}

LISTING 4-22 SQL injection/LISTING 4-22 SQL injection/Program.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ static void Main(string[] args)
5353
Console.ReadKey();
5454
}
5555
}
56-
}
56+
}

LISTING 4-23 Parameterized query/LISTING 4-23 Parameterized query/Program.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ static void Main(string[] args)
5555
Console.ReadKey();
5656
}
5757
}
58-
}
58+
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Configuration;
4-
using System.Data;
5-
using System.Linq;
6-
using System.Threading.Tasks;
7-
using System.Windows;
1+
using System.Windows;
82

93
namespace MusicTracks
104
{
@@ -14,4 +8,4 @@ namespace MusicTracks
148
public partial class App : Application
159
{
1610
}
17-
}
11+
}

LISTING 4-24 Asynchronous access/LISTING 4-24 Asynchronous access/MainWindow.xaml.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ namespace MusicTracks
1010
/// </summary>
1111
public partial class MainWindow : Window
1212
{
13-
1413
// You will need to edit this string to match your database file
1514
string connectionString = "Server=(localdb)\\mssqllocaldb;" +
1615
"Database=MusicTracksContext-e0f0cd0d-38fe-44a4-add2-359310ff8b5d;" +
@@ -71,4 +70,4 @@ private async void ViewDatabaseButton_Click(object sender, RoutedEventArgs e)
7170
}
7271
}
7372
}
74-
}
73+
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Configuration;
4-
using System.Data;
5-
using System.Linq;
6-
using System.Threading.Tasks;
7-
using System.Windows;
1+
using System.Windows;
82

93
namespace NASAAstronomyPictureOfTheDay
104
{
@@ -14,4 +8,4 @@ namespace NASAAstronomyPictureOfTheDay
148
public partial class App : Application
159
{
1610
}
17-
}
11+
}

LISTING 4-25 NASA JSON/LISTING 4-25 NASA JSON/MainWindow.xaml.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,25 @@ public async Task displayUrl(string url)
3939
public class ImageOfDay
4040
{
4141
public string date { get; set; }
42+
4243
public string explanation { get; set; }
44+
4345
public string hdurl { get; set; }
46+
4447
public string media_type { get; set; }
48+
4549
public string service_version { get; set; }
50+
4651
public string title { get; set; }
52+
4753
public string url { get; set; }
4854
}
4955

5056
async Task<ImageOfDay> GetImageOfDay(string imageURL)
5157
{
5258
string NASAJson = await readWebpage(imageURL);
5359

54-
ImageOfDay result = JsonConvert.DeserializeObject< ImageOfDay>(NASAJson);
60+
ImageOfDay result = JsonConvert.DeserializeObject<ImageOfDay>(NASAJson);
5561

5662
return result;
5763
}
@@ -78,4 +84,4 @@ private async void LoadButtonClicked(object sender, RoutedEventArgs e)
7884
}
7985
}
8086
}
81-
}
87+
}

LISTING 4-26 XML elements/LISTING 4-26 XML elements/Program.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ static void Main(string[] args)
3333
Console.ReadKey();
3434
}
3535
}
36-
}
36+
}

0 commit comments

Comments
 (0)