Posts

C# - Intersect and Except in Linq form

Something the intersect and except won't be enough for some comparisons. we will have to dig in for some particular type of values like ids, name, etc. Below is an example of this. Intersect in linq form- A.Intersect(B) => gives stuff in  both A and B             var intersect = A.Where(x => B.Select(y => y.Id).Contains(x.Id)).ToList(); Except in linq form- A.Except(B) => gives stuff in  A and NOT B             var intersect = A.Where(x => !B.Select(y => y.Id).Contains(x.Id)).ToList();

Reading and writing a CSV file in c # using csvHelper Example

Below is an example to write and read a csv file using csvHelper Library in c sharp. First you will have to include the csvHelper lib in to your project by going in to NuGet packages in your project and adding it. Once you don’t that you can examine the below program and implement the program. NB:- The below is just a snippet of code and the objects are not declared properly. So please make necessary changes before running the program. For writing a file- public void WriteFile( Data data)         {             String pathIp = “input_your_filePath”;             StreamWriter writeIp = new StreamWriter (pathIp);             CsvWriter cswIp = new CsvWriter (writeIp);                                                 // this below line is for inserting a header in your CSV file. I am just writing “Data-table”             cswIp.WriteField( "Data-table" );             cswIp.NextRecord();             for ( int i = 0; i < data_length_rows;

Performance evaluation of reading/writing data from CSV and Excel in C sharp

Recently I did a performance evaluation(not part of my plan) on the performance In reading CSV and Excel files and there was a clear winner. I did this test because I had to process a hell lot of data which was given to me was in excel format. I used C# as my platform to start and immediately I found some libraries such as Interop to help me out. It was pretty easy. At the beginning I used only a small portion of the data and when I started using the original files which has like thousands of records, it started to take a lot of time. So I has a preprocessing function where I write this data to a CSV file. And when I started to read from the CSV, it was very fast. Instead of taking some five minutes, now it take less than 10 seconds. I used the csvHelper lib to help me out and it was pretty easy. Even though it might be a one time execution in the production system, while you are doing the coding you might have to execute it a hundred times. So I would suggest to convert it into a CS

How to return two objects at the same time in c sharp or Example of Tuple in c sharp

I found ‘Tuple’ to be  a very special , where you want to return two objects in the same function itself. I will explain with the help of below code. My aim in the below code is to return two objects in the same function. Lets consider those two objects are emp_Permanent and emp_Temp which I need when I call a function. These two objects are of the class Employee. public Tuple < Employee , Employee > splitEmployee( Employee employee)         {                                                                               // here I am splitting my employee objects in to two other objects                                                        // let’s assume that the new objects are emp_Permanent and emp_Temp                                                                       return new Tuple < Employee , Employee >( emp_Permanent, emp_Temp );         } Now in your main code, call this function as below. var splitData =  splitEmp

How to calculate the run time/time required for a program in visual studio or in C Sharp

I recently started programming in C# and I found it far better than Java already. To find the time took by your code , you will have to insert the below snippet . For more information, you can go to the msdn link. /* importing the lib*/ using System.Diagnostics; /* creating the object of Stopwatch, where we can it to calculate the time*/ Stopwatch stopwatch = new Stopwatch (); stopwatch.Start();// Start the time stopwatch.Stop();// Stop the time TimeSpan ts = stopwatch.Elapsed;             long elapsedMilliseconds;             elapsedMilliseconds = stopwatch.ElapsedMilliseconds; /*Conversion of elapsed time to milliseconds. We can even convert it in to minutes or hours. For more information please check the below link to msdn*/ Console .WriteLine( "RunTime " + elapsedMilliseconds); Msdn Link

Startx Gives error in Raspberry Pi - Authority issues

Here is one of the solution for the problem. This error can be because of the permission issues of the Authority file.So here we need to give permission for the files.So the steps are- Login with your Username and Password in terminal Type : sudo chmod 777 /home/pi This will provide enough permission for the authority file to run. Hope this helps.

Configuring Edimax Wifi Dongle in Raspberry Pi 2

Image
I am going to be very quick here- Open the terminal  Type : sudo su Type in the root password(or your password) Type :  nano /etc/network/interfaces This will open the nano interfaces.Here you need to configure you Wifi Settings as shown below- PS - Please tyoe in your SSID and password for your WiFi connection. Once you have made your changes use Ctrl+X and "Y" to save the file. Use this command to restart the service- sudo service networking reload Final step is to Restart the system