# 03 Read a csv – demo explained https://github.com/howest-mct/DEVPROG_DEMO_03/tree/main/Demo_03_Readacsv [toc] # Demo This is a screencast on how to read from a csv file - no sound. ::: warning Be careful: in the demo, the static functions to get data are still in the Model class. Your functions should be in a repository class as explained in lab! ::: [![](https://hackmd.io/_uploads/H1w2UkvGo.png)](![](https://hackmd.io/_uploads/r1G6IkDfi.png) ) # Python ![](https://hackmd.io/_uploads/SkGU9aIGi.png) # C# ## Model ![](https://hackmd.io/_uploads/H1vSoa8Mj.png) To get the code above to be compiled, we need to add two extra using statements: ![](https://hackmd.io/_uploads/rkZvip8zj.png) * System.IO stands for Input/Output, and is required to use the StreamReader object. * System.Reflection enables code to be compiled at runtime, and is needed to get the assembly info. ![](https://hackmd.io/_uploads/rkOvi6Lfi.png) * For now, all you have to understand from these lines of code, is that: * **typeof(…)** needs the `<classname>`, and * **GetManifestResourceStream(…)** needs a string of the following format: `“<project_name>.<foldername>.<filename_with_extension>”` Eg. in this case: * <project_name> Demo_03_Readacsv * <foldername> the csv file is in a folder named Assets * <filename_with_ext> beerlist.csv * The ‘using’ block makes sure the file is seized on by the program, and is automatically closed / released at the end of that block. ## Xamarin specific: display using layout We will display the list of beers by making use of a ListView control. This is a control that’s used to display a list of objects. ### MainPage.xaml In your xaml file (= visual layout), you can find the ListView control that was added: ![](https://hackmd.io/_uploads/HJUzn6Izo.png) The ListView gets a name to make it accessible from code ### MainPage.xaml.cs The code behind file will now use the name of the list to fill it with data ![](https://hackmd.io/_uploads/rJzr2pIzi.png) The ItemsSource property contains the collection of items the ListView should display ## The result If you start the application, you can see a list of beers. The details of the visualization (such as colors) can vary among the different operation systems and are based on the settings of the device. ![](https://hackmd.io/_uploads/SJ4dhpLfj.png)