I have two files that are being read into separate arrays such as:
String[] leaseName2 = new String[1000];
String[] fieldName2 = new String[1000];
String[] reservoir2 = new String[1000];
String[] operator2 = new String[1000];
String[] county2 = new String[1000];
String[] state2 = new String[1000];
String[] majo2 = new String[1000];
String[] resvCatgory2 = new String[1000];
String[] netOil2 = new String[1000];
String[] netGas2 = new String[1000];
String[] netNGL2 = new String[1000];
String[] leaseName = new String[1000];
String[] fieldName = new String[1000];
String[] reservoir = new String[1000];
String[] operator1 = new String[1000];
String[] county = new String[1000];
String[] state = new String[1000];
String[] majo = new String[1000];
String[] resvCatgory = new String[1000];
String[] netOil = new String[1000];
String[] netGas = new String[1000];
String[] netNGL = new String[1000];
I then merge the two files using Linq, to merge two of the matching arrays such as netOil and netOil2 that give me a double answer. There are a bunch of different rows of data that are matched by the same seqNum arrays.
String[] seqNum2 = new String[1000]; //This will be the identifier
String[] seqNum = new String[1000]; //This will be the identifier
The problem I am having is outputting all of the corresponding data such as leaseName[] and fieldname[] and reservoir[] with the identifying seqNum array. Here is my Linq code:
private void executeBtn_Click(object sender, EventArgs e)
{
//NET OIL VARIANCE MATHEMATICS
if (netOilRadBtn.Checked)
{
using (var sw = new StreamWriter("testNetOil.csv"))
{
var items = netOil.Zip(seqNum, (oil, seq) => new {Oil = oil, Seq = seq });
var items2 = netOil2.Zip(seqNum2, (oil, seq) => new { Oil = oil, Seq = seq });
sw.WriteLine("Lease Name, Field Name, Reservoir, Operator, County, ST, Majo, Resv Cat, Discount Rate, Net Oil Interest, Net Gas Interest, Working Interest, Gross Wells, Ultimate Oil, Ultimate Gas, Gross Oil, Gross NGL, Gross Gas, Net Oil, Net Gas, Net NGL, Revenue To Int., Oper. Expense, Total Invest., Revenue Oil, Revenue Gas, Operating Profit, Revenue NGL, Disc Net Income, SEQ, Well ID, INC ASN, Life Years, Own Qual, Production Tax, NET OIL VARIANCE");
foreach (var item in items2.Join(items, i => i.Seq, i => i.Seq, (a, b) => new
{
SeqID = a.Seq,
Answer = this.GetTheAnswer(Convert.ToDouble(a.Oil), Convert.ToDouble(b.Oil)),
//OilNum1 = a.Oil, GIVES FIRST OIL FROM NET OIL ARRAY 1, item.oilnum1 will print out first oil #
//OilNum2 = b.Oil, GIVES SECOND OIL FROM NET OIL ARRAY 2, item.OilNum2 ********
}))
{
sw.WriteLine(item.SeqID + "," + item.Answer); //this prints out the seqNum and Answer that I want to match with all of the other data in the arrays
/* commented out to see what I've tried
int x = listHead;
x.Equals(item.SeqID);
while (x != -1)
{
sw.WriteLine("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}, {13}, {14}, {15}, {16}, {17}, {18}, {19}, {20}, {21}, {22}, {23}, {24}, {25}, {26}, {27}, {28}, {29}, {30}, {31}, {32}, {33}, {34}, {35}, {36}",
QuoteString(leaseName[x]), fieldName[x], QuoteString2(reservoir[x]), operator1[x], county[x], state[x], majo[x], resvCatgory[x], disRate[x], netOil2Int[x], netGas2Int[x], workingInt[x], grossWells[x]
, ultOil[x], ultGas[x], grossOil[x], grossNGL[x], grossGas[x], netOil[x], netGas[x], netNGL[x], revToInt[x], operExpense[x], totInvest[x], revOil[x], revGas[x], operatingProfit[x],
revNGL[x], discNetIncome[x], seqNum[x], wellID[x], incASN[x], lifeYears[x], ownQual[x], prodTax[x], item.SeqID, item.Answer);
x = pointers[x];
//sw.WriteLine(item);
}*/
}
sw.Close();
}
}
I am not able to print out all of the data with the matching seqNum in the foreach loop, so I tried to create another loop but that was printing out a lot of extra data that was not useful. If anyone has any idea on how to print out all of the data with the seqNum after I get the Answer with the Linq code, I would appreciate it if you could let me know. Any help would be greatly appreciated.
I would suggest that you learn and practice some basic intro programming and OOP before attempting to use C# and LinQ.
First of all, the sole idea of having 11 arrays of strings is disgusting. You should learn how to create a proper data model and do so.
public class MyRecord
{
public int SeqNum {get;set;} // Notice the proper case in property names
public string LeaseName {get;set;}
public string FieldName {get;set;}
public string Reservoir {get;set;}
//... Etc.
}
Then, take a second to analyze whether it is a good idea that ALL your properties be string. For example, if a property can only have numeric values, it would be better that you strongly type that and use int or double. If a property can only have "true" or "false" values, that would be a bool, and so on.
The problem I am having is outputting all of the corresponding data
such as leaseName[] and fieldname[] and reservoir[] with the
identifying seqNum array.
That's because your data is modeled in the worst possible way. If you create a class like above, you will not have that problem, because all data pertaining to the same record will be in the same instance of this class. Then:
List<MyRecord> File1 {get;set;}
List<MyRecord> File2 {get;set;}
var myrecord = File1.FirstOrDefault(x => x.SeqNum == someSeqNum);
var leasename = myrecord.LeaseName;
var reservoir = myrecords.Reservoir;
//... etc
See how easy life actually is?
To top it all, PLEASE, for the sake of mankind, REMOVE your business logic from the code behind the UI. Create proper SERVICES to do that, with relevant methods with relevant parameters, in order to isolate this functionality and be able to REUSE it.
private void executeBtn_Click(object sender, EventArgs e)
{
MyService.ProcessRecords(relevant,parameters,from,the,UI);
}
Related
I'm trying to sort a list based on the price for each item in the list.
Here's what I want my output to look like:
ROLLS_ROYCE1 -- 6.608 €
ROLLS_ROYCE3 -- 4.956 €
ROLLS_ROYCE2 -- 0.826 €
However, here's what the current output actually is:
ROLLS_ROYCE1 -- 6.608 €
ROLLS_ROYCE2 -- 0.82 €
ROLLS_ROYCE3 -- 4.956 €
Here's my code:
public void MyFunction()
{
List<string> mylist = new List<string>(new string[]
{
"ROLLS_ROYCE1 -- 0,826 € -- 8 PCS -- 14:02:53.876",
"ROLLS_ROYCE2 -- 0,826 € -- 1 PCS -- 17:02:53.888",
"ROLLS_ROYCE3 -- 0,826 € -- 6 PCS -- 18:09:55.888"
});
foreach (string f in mylist)
{
decimal b = Convert.ToDecimal(GetPrice(f), CultureInfo.GetCultureInfo("de-DE")) * Convert.ToDecimal(GetPieces(f));
tradesforbigbuyslist += GetName(f) + " -- " + b.ToString() + " €" +
Environment.NewLine;
}
string[] splittedt2 = tradesforbigbuyslist.Split(new string[] {
System.Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
listBox3.DataSource = splittedt2;
}
public string GetPrice (string sourceline)
{
string newstring = sourceline;
string test1 = newstring.Replace(FetchThemAll.SubstringExtensions.Before(newstring, "--"), "");
string textIWant = test1.Replace("--", "");
string finalPrice = FetchThemAll.SubstringExtensions.Before(textIWant, "€");
return finalPrice;
}
public string GetPieces(string sourceline)
{
string ertzu = sourceline;
string ertzu1 = FetchThemAll.SubstringExtensions.Between(ertzu, "€", "PCS");
string ertzu2 = ertzu1.Replace("--", "");
return ertzu2;
}
public string GetName(string sourceline)
{
string barno = FetchThemAll.SubstringExtensions.Before(sourceline, "--");
return barno;
}
How can I sort these strings correctly?
You could simplify a lot of this work by representing each line of input as a class with relevant properties like this. If accuracy is super important like with dealing real money then fixed precision data type should represent the price. However I am using double below for simplicity.
public class Car {
public string Name;
public short Pieces;
public double Price;
}
Then you would parse them at the beginning and have a list of these Car items. Assuming the Price above represents the desired value you wish to sort by the list you seek would be obtained by the following linq query.
var cars = new List<Cars>(); //Assumed definition
var frenchCulture = CultureInfo.CreateSpecificCulture("fr-FR"); //For Euros symbol usage later
//Parse Logic in Between
var sortedCars = cars.OrderByDescending(c => c.Price); //Linq Query yielding IEnumerable. If you must have a list simply append toList()
Then your output might be set like this.
foreach (var car in sortedCars)
// output with string.format("{0} -- {1}", car.Name, car.Price.ToString("C3", frenchCulture))
Warning that this code was not tested but should be approximately correct. I did do some research for the string format.
Well, the format of your strings in mylist looks consistent enough that something like this might work (without using extension methods or Regex at all):
var parsed = mylist.Select(line => line.Split(new[] { " -- " }, StringSplitOptions.None)).Select(parts => new
{
Name = parts[0],
Price = Convert.ToDecimal(parts[1].Substring(0, parts[1].IndexOf(' '))),
Pieces = Convert.ToInt32(parts[2].Substring(0, parts[2].IndexOf(' ')))
});
var sorted = parsed.OrderByDescending(x => x.Price * x.Pieces);
Then you can do whatever you want with sorted - e.g. convert the items back to strings and display them in listBox3.
Here is what I did: I have tested this and it seems to work.
public void MyFunction()
{
List<string> mylist = new List<string>(new string[]
{
"ROLLS_ROYCE1 -- 0,826 € -- 8 PCS -- 14:02:53.876",
"ROLLS_ROYCE2 -- 0,826 € -- 1 PCS -- 17:02:53.888",
"ROLLS_ROYCE3 -- 0,826 € -- 6 PCS -- 18:09:55.888"
});
var map = new Dictionary<string, double>();
foreach (string f in mylist)
{
var inputs = f.Split(" -- "); //Creates a list of strings
var unitPrice = Convert.ToDouble(inputs[1].Split(' ')[0]);
var numUnits = Convert.ToDouble(inputs[2].Split(' ')[0]);
var key = inputs[0];
if(map.ContainsKey(key)) map[key] = numUnits*unitPrice;
else map.Add(key, numUnits*unitPrice);
}
var sortedMap = map.OrderByDescending(x=>x.Value);
foreach(var item in sortedMap){
Console.WriteLine($"{item.Key} -- {item.Value} €");
}
}
It may be overkill for you, but what I usually do in cases like this is create a class that knows how to parse one of those lines into strongly typed properties, like Name, Price, Quantity, etc. Usually I create a static method named Price that takes in an input string and returns an instance of the class.
In this case it would look something like:
public class Item
{
public string Name { get; set; }
public decimal Price { get; set; }
public int Quantity { get; set; }
public TimeSpan Time { get; set; }
public decimal Total => Price * Quantity;
public static Item Parse(string input)
{
if (input==null) throw new ArgumentNullException();
var parts = input
.Split(new[] {"--", " ", "€", "PCS"},
StringSplitOptions.RemoveEmptyEntries);
if (parts.Length != 4)
throw new ArgumentException(
"Input must contain 4 sections separated by \"--\"");
decimal price;
if (!decimal.TryParse(parts[1], out price))
throw new ArgumentException(
"Price must be a valid decimal in the second position");
int quantity;
if (!int.TryParse(parts[2], out quantity))
throw new ArgumentException(
"Quantity must be a valid integer in the third position");
TimeSpan time;
if (!TimeSpan.TryParse(parts[3], out time))
throw new ArgumentException(
"Time must be a valid TimeSpan in the fourth position");
return new Item
{
Name = parts[0],
Price = price,
Quantity = quantity,
Time = time
};
}
}
With the work being done in the class, our main code is simplified tremendously:
List<string> mylist = new List<string>(new string[]
{
"ROLLS_ROYCE1 -- 0,826 € -- 8 PCS -- 14:02:53.876",
"ROLLS_ROYCE2 -- 0,826 € -- 1 PCS -- 17:02:53.888",
"ROLLS_ROYCE3 -- 0,826 € -- 6 PCS -- 18:09:55.888"
});
List<Item> orderedItems = mylist
.Select(Item.Parse)
.OrderByDescending(item => item.Total)
.ToList();
And then displaying the items would be as simple as:
orderedItems.ForEach(item => Console.WriteLine($"{item.Name} -- {item.Total} €"));
Output
Is there a way to compare 2 models and only show the differences, for example what has been updated, added or deleted?
For example, in the models below, I have created a number of Sample models:
var grocers1 = new List<Grocer>();
var grocer1 = new Grocer
{
Id = 1,
Expenditure = 500,
Name = "Bob"
};
grocers1.Add(grocer1);
var grocers2 = new List<Grocer>();
var grocer2 = new Grocer
{
Id = 1,
Expenditure = 300,
Name = "Bob"
};
grocers2.Add(grocer2);
var fruits = new List<Fruit>();
var fruit1 = new Fruit();
fruits.Add(fruit1);
var orders1 = new List<Order>();
var order1 = new Order
{
Id = 1,
SampleId = 1,
Fruits = fruits
};
var order2 = new Order
{
Id = 1,
SampleId = 1,
Fruits = fruits
};
orders1.Add(order1);
orders1.Add(order2);
var orders2 = new List<Models.Documents.Order> {order1};
var sample = new Sample
{
Id = 1,
Date = Convert.ToDateTime("2018-10-23"),
Grocers = grocers1,
Orders = orders1
};
var changedSample = new Sample
{
Id = 1,
Date = Convert.ToDateTime("2018-10-22"),
Grocers = grocers2,
Orders = orders1
};
var otherChangedSample = new Sample
{
Id = 1,
Date = Convert.ToDateTime("2018-10-23"),
Grocers = grocers1,
Orders = orders2
};
So if I compare sample to changedSample it should just show the Date has changed from 2018-10-23 to 2018-10-22 and that the Expenditure has changed from 500 to 300.
Then if I was to compare sample to otherChangedSample it should show that order2 has been removed.
And then finally if I was to compare otherChangedSample to sample it would show that order 2 had been added.
I have tested with AutoMapper this is great for comparing the same base model, excluding lists, it nicely highlights the changes.
I then tried Compare-Net-Objects which is good, this time does take into account lists and highlights the changes, but only if the list count stays the same. It will identify the list count change but not tell you the values of what has been removed or the values of what has been added.
Any help would be much appreciated.
You can use reflection and extension method as well:
var sample = new Sample
{
Id = 1,
Date = Convert.ToDateTime("2018-10-23"),
Grocers = grocers1,
Orders = orders1
};
var otherChangedSample = new Sample
{
Id = 1,
Date = Convert.ToDateTime("2018-10-23"),
Grocers = grocers1,
Orders = orders2
};
class Variance
{
public string Prop { get; set; }
public object valA { get; set; }
public object valB { get; set; }
}
List<Variance> rt = sample.DetailedCompare(otherChangedSample);
using System.Collections.Generic;
using System.Reflection;
static class extentions
{
public static List<Variance> DetailedCompare<T>(this T val1, T val2)
{
List<Variance> variances = new List<Variance>();
FieldInfo[] fi = val1.GetType().GetFields();
foreach (FieldInfo f in fi)
{
Variance v = new Variance();
v.Prop = f.Name;
v.valA = f.GetValue(val1);
v.valB = f.GetValue(val2);
if (!v.valA.Equals(v.valB))
variances.Add(v);
}
return variances;
}
}
have you coded your model classes yourself? If not, then you have to deal with reflection (could be slow and you have to do a lot of programming to cover all data types), or with serialization (serialize as string and do a string compare).
If you can extend your classes, then I would add a method to every single class:
internal void TrackChange(T other, List<Change> changes)
This method in your class Sampe would look like:
void TrackChange(Sample other, List<Change> changes)
{
if (this.Id != other.Id) changes.add(new Change(...));
if (this.Date != other.Date) changes.add(new Change(...));
if (this.Grocers.count != other.Grocers.count) changes.add(new Change(...)); // number of items has changed
for (int i = 0; i < math.min(this.grocers.count, other.grocers.count); i++)
this.grocers[i].TrackChange(other.grocers[i], changes);
....
}
The Grocer class has its onwn TrackChange method. and so on.
This is some coding, but the most efficient and you can handle all cases yourself. for example if the order of grocers in your list does not mind, then you can iterate all grocers of this list and try to find the corresponding grocer in the others list (e.g. by Id) and call the TrackChange then.
How to split product array string using , and save key value pair in dictionary or list. String in cookie is:
cookieValue ="12&150&pid=1,name=abc,size=2gm Sachet,price=50,image=Pouch.jpg,quantity=1&pid=2,name=xyz,size=200gm Packet,price=50,image=small.jpg,quantity=2"
products array is as below:
[0] "12"
[1] "150"
[2] "pid=1,name=abc,size=2gm Sachet,price=50,image=Pouch.jpg,quantity=1"
[3] "pid=2,name=xyz,size=200gm Packet,price=50,image=small.jpg,quantity=2"
Code for processing cookie:
if(HttpContext.Request.Cookies["Cart"]!= null)
{
var cookieValue = Request.Cookies["Cart"].Value;
string[] products = cookieValue.Split('&');
var len = products.Length;
for(int x=2;x<=len;x++)
{
string s1 = products[x];
}
}
Hope this helps.
You cannot use dictionary as there are duplicate keys. But you can use List of KeyValuePairs.
var products = cookieValue.Split('&');
var keyValueList = new List<KeyValuePair<string, string>>();
foreach (var product in products)
{
var sequence = product.Split(',').ToList();
var isValidSequence = sequence.Count > 1;
if (!isValidSequence) continue;
sequence.ForEach(s =>
keyValueList.Add(new KeyValuePair<string, string>(s.Split('=')[0], s.Split('=')[1]))
);
}
In your example, splitting the input string at the & produces an array of 4 elements, so assuming that the first half of this array represents something that you want to skip and the second half is the Product itself with the pid field to use as the Key for the KeyValuePair structure you can transform that string in a Dictionary<int, Product> in this way
public class Product
{
public int ID {get;set;}
public string Name {get;set;}
public string Size {get;set;}
public decimal Price {get;set;}
public string Image {get;set;}
public int Quantity {get;set;}
}
Dictionary<int, Product> dicProducts = new Dictionary<int, Product>();
string[] products = cookieValue.Split('&');
var len = products.Length;
int half = len / 2;
for(int x=half;x<len;x++)
{
string[] productData = products[x].Split(',');
Product p = new Product()
{
ID = Convert.ToInt32(productData[0]);
Name = productData[1];
Size = productData[2];
Price = Convert.ToDecimal(productData[3]);
Image = productData[4];
Quantity = Convert.ToInt32(productData[5]);
}
dicProducts.Add(p.ID, p);
}
This is a very simple code to traverse the input data and I have added no kind of check on the input data to not overcomplicate the example. In a real world application scenario you should add a lot of checks. For example, the input data should be divisible exactly by two, the strings found in the product part should be checked for their completemess and validity.
I can't figure out how can I read items from the text file and put them into an int array. My objective is to count what is the average grade. To do so, I need to read the number which tells me how many grades does 1 student have, and then using that amount, read the grades themselves. For example, first column shows the amount of the grades, all remaining columns shows grades:
5;8;7;9;10;4
3;8;9;10
2;5;9
The code I wrote:
static void ReadData(out Student[] Student, out Faculty Faculty)
{
using (StreamReader read = new StreamReader(#"Data", Encoding.GetEncoding(1257)))
{
string line = null;
Student = new Student[Faculty.CMax];
Faculty = new Faculty();
while (null != (line = read.ReadLine()))
{
string[] values = line.Split(';');
string lastname = values[0];
string name = values[1];
string group = values[2];
int amount = int.Parse(values[3]);
int grades = int.Parse(values[4]);
Student studen = new Student(lastname, name, group, amount, grades);
Student.Take[Faculty.AmountOfStudents++] = studen;
}
}
}
I know that int[] grades = int.Parse(values[4]); is the problem. But I don't know how to fix it. Probably a newbie problem, thanks for the help.
After your clarification, it seems that you want to take:
Smith;John;XYZ;4;2;4;6;8
And retrieve the array of [2,4,6,8] so you can get the average from that.
If you can't do what I mention in my comment, then here's a workaround. Since the number of grades is irrelevant, just ignore it, and you'll recognize that you need an int array which contains 4 fewer items than the original. Then it's just a matter of copying them:
string[] fields = val.Split(';');
int[] grades = new int[fields.Length - 4];
for (int i = 4; i < fields.Length; ++i)
{
grades[i - 4] = int.Parse(fields[i]);
}
Or some other alternate versions if you're into LINQ:
string[] fields = val.Split(';');
int[] grades = Enumerable.Range(4, fields.Length - 4)
.Select(i => int.Parse(fields[i]))
.ToArray();
string[] fields = val.Split(';');
int[] grades = fields.Select((s, i) => new { s, i })
.Where(x => x.i >= 4)
.Select(x => int.Parse(x.s))
.ToArray();
I'm trying to output a certain answer with matching data using linq. Here's the code,
public string[] netoilVar(string[] final)
{
var items = netOil.Zip(seqNum, (oil, seq) => new {Oil = oil, Seq = seq });
var items2 = netOil2.Zip(seqNum2, (oil, seq) => new { Oil = oil, Seq = seq });
List<string> vars = new List<string>();
foreach (var item in items2.Join(items, i => i.Seq, i => i.Seq, (a, b) => new
{
x = a.Seq,
y = this.GetTheAnswer(Convert.ToDouble(a.Oil), Convert.ToDouble(b.Oil)),
oilnum1 = a.Oil,
oilnum2 = b.Oil,
}))
{
vars.Add(item.y + "," + item.oilnum1 + "," + item.oilnum2);
final = vars.ToArray();
}
return final;
}
//BEGINS THE EXECUTE BUTTON METHOD
private void executeBtn_Click(object sender, EventArgs e)
{
//NET OIL VARIANCE MATHEMATICS
if (netOilRadBtn.Checked)
{
int i = listHead;
string[] x = new String[1000];
StreamWriter sw = new StreamWriter("testNetOil.csv");
sw.WriteLine("Lease Name, Field Name, Reservoir, Operator, County, ST, Majo, Resv Cat, Discount Rate, Net Oil Interest, Net Gas Interest, Working Interest, Gross Wells, Ultimate Oil, Ultimate Gas, Gross Oil, Gross NGL, Gross Gas, Net Oil, Net Gas, Net NGL, Revenue To Int., Oper. Expense, Total Invest., Revenue Oil, Revenue Gas, Operating Profit, Revenue NGL, Disc Net Income, SEQ, Well ID, INC ASN, Life Years, Net Oil Variance., Current Year's Net Oil, Last Year's Net Oil");
//Loops until the end of the list, printing out info
while (i != -1)
{
sw.WriteLine("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}, {13}, {14}, {15}, {16}, {17}, {18}, {19}, {20}, {21}, {22}, {23}, {24}, {25}, {26}, {27}, {28}, {29}, {30}, {31}, {32}, {33}, {34}",
QuoteString(leaseName[i]), fieldName[i], QuoteString2(reservoir[i]), operator1[i], county[i], state[i], majo[i], resvCatgory[i], disRate[i], netOil2Int[i], netGas2Int[i], workingInt[i], grossWells[i]
, ultOil[i], ultGas[i], grossOil[i], grossNGL[i], grossGas[i], netOil[i], netGas[i], netNGL[i], revToInt[i], operExpense[i], totInvest[i], revOil[i], revGas[i], operatingProfit[i],
revNGL[i], discNetIncome[i], seqNum[i], wellID[i], incASN[i], lifeYears[i], ownQual[i], netoilVar(x)[i]);
i = pointers[i];
}
sw.Close();
}
I'm getting an IndexOutOfRangeException on the while loop that is printing out all the data, most specifically on the netoilVar(x)[I] part. Is there any way I can get the correct index there so I don't get the exception?
While loops can be dangerous as you have seen here. I would highly recommend abstracting out your data to make things easier to work with.
Model your data like this:
public class MyData
{
public string LeaseName { get; set; }
public int UltOil { get; set; }
public int UltGas { get; set; }
public static string GetHeaders()
{
return "LeaseName, UltOil, UltGas";
}
public override string ToString()
{
return string.Join(",", LeaseName, UltOil, UltGas);
}
}
Then when writing out your csv file use the model like this:
private void Foo()
{
//NET OIL VARIANCE MATHEMATICS
if (netOilRadBtn.Checked)
{
var input = new List<MyData>(); // <-- Fill in your data here.
StreamWriter sw = new StreamWriter("testNetOil.csv");
sw.WriteLine(MyData.GetHeaders());
//Loops until the end of the list, printing out info
foreach (var item in input)
{
sw.WriteLine(item);
}
sw.Close();
}
}
Obviously this is abbreviated, you will want to include all your fields, name and type them appropriately.