Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question to my teacher's C# code: My teacher has set System.IO to SIO and later use it to read from a txt file. I was

Question to my teacher's C# code:

My teacher has set "System.IO" to "SIO" and later use it to read from a txt file.

I was wondering why that is and why it should be done like this:

**************************************************************************************

string filename;

filename = SIO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "babynames.txt");

SIO.StreamReader reader = null;

**************************************************************************************

Thank you!

The context of the code where we are to show the first 10 names from the txt file.

______________________________________________________________

using SIO = System.IO; namespace Lab1 { ///  /// Interaction logic for MainWindow.xaml ///  public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); Loaded += new RoutedEventHandler(MainWindow_Loaded); } void MainWindow_Loaded(object sender, RoutedEventArgs e) { string filename; filename = SIO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "babynames.txt"); SIO.StreamReader reader = null; try { reader = new SIO.StreamReader(filename); { for (int i = 0; i < 10; ++i) { lstDecadeTopNames.Items.Add(reader.ReadLine()); } } } finally { if (reader != null) reader.Close(); } } } } 

__________________________________________________________________________

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions