Here is what I have:
How do you pass List
Java
class ProcessClaims
{
public static ListMMORecord> listDataMMO = new ListMMORecord>();
public static ListPHCSRecord> listDataPHCS = new ListPHCSRecord>();
public static ListPHCRecord> listDataPHC = new ListPHCRecord>();
public static ListMMORecord> listDataPHS = new ListMMORecord>();
public static ListMMORecord> listDataGLB = new ListMMORecord>();
public static ListPHCRecord> listDataNotcovered = new ListPHCRecord>();
public static ListMMORecord> listDataDEL = new ListMMORecord>();
public static ListPHCRecord> listDataMC1 = new ListPHCRecord>();
public static ListMMORecord> listDataHC = new ListMMORecord>();
public static ListPHCSRecord> listDataMultiplan = new ListPHCSRecord>();
The MMORecord, PHCSRecord, PHCRecord are classes.
Then I use it to pass to a Method.VB.NET
CreateExcelXML.CreateNewSheet(@"E:\MMOExtract\Extract\" + sFilename + Program.extractEndDate + ".xlsx",
sheet, sheetNum, header, ProcessClaims.listDataPHCS, setNumber);
Here is the Method.
public static void CreateNewSheet(string path, string sheetName, UInt32Value sheetNum,
Liststring> header, ListPHCSRecord> listData, Listint> setNumber)
How can I pass this List so I do not have to have a Method for each List? I have 10 List's so I
would have to have 10 Methods. Then this goes to another Method and I will have to have 10 more Methods.
It will all be duplicate code except for the List which references a class.
How can I do this so I can only have one general Method for all 10? It is passed as a reference, correct?
Thanks for the help ahead of time. I am still learning C# and .NET.
Arep
VulpesRank #55 · 29.2K reputationPosted Jan 12, 2012, 1:25 AM EST
VulpesRank #55 · 29.2K reputationPosted Jan 6, 2012, 5:08 AM EST
A RepaskyRank #8,108 · 228 reputationPosted Jan 6, 2012, 5:26 AM EST
Error 1 foreach statement cannot operate on variables of type 'T' because 'T' does not contain a public definition for 'GetEnumerator'
The code at that location is and the problem is at the second foreach statement:
Row row; Cell cell; uint rowCnt = 2; string cl = ""; //Loop through the class foreach (var curClass in listData) { row = new Row(); int idx = 0; foreach (var item in curClass) { //Set the cell location if (idx >= 26) cl = "A" + Convert.ToString(Convert.ToChar(65 + idx - 26)); else cl = Convert.ToString(Convert.ToChar(65 + idx)); cell = new Cell(); //ETC. Again, thanks, ArepVulpesRank #55 · 29.2K reputationPosted Jan 6, 2012, 5:57 AM EST
A RepaskyRank #8,108 · 228 reputationPosted Jan 6, 2012, 6:07 AM EST
Error 1 The type 'MMOExtract.PHCSRecord' cannot be used as type parameter 'T' in the generic type or method 'MMOExtract.CreateExcelXML.CreateNewSheet
Thanks, I thought we had it.
Arep
VulpesRank #55 · 29.2K reputationPosted Jan 6, 2012, 6:12 AM EST
To use them generically, they either need to implement some common interfaces or inherit from a common base class.
A RepaskyRank #8,108 · 228 reputationPosted Jan 6, 2012, 12:05 PM EST
>. So I am going that way.
Thanks,
Arep
VulpesRank #55 · 29.2K reputationPosted Jan 6, 2012, 12:13 PM EST
If the code in the nested foreach statement was working before you tried to genericize the method, then PHCSRecord must implement one of these interfaces.
A RepaskyRank #8,108 · 228 reputationPosted Jan 6, 2012, 12:17 PM EST
I have to leave now and will work over the weekend. Go to game tonight though.
Arep
A RepaskyRank #8,108 · 228 reputationPosted Jan 7, 2012, 7:22 AM EST
> to work. So I would like to continue with your way. I am attaching one of the classes, so you can see how they are created. It was the Lead Programmer that I work with that told me to use the nested List's, and he really pushes to go his way.
So can someone help me? I need to pass the List with a Class to a method,
Thanks for any help.
Arep
VulpesRank #55 · 29.2K reputationPosted Jan 7, 2012, 9:19 AM EST
Even if it now works OK for the PHCSRecord class, it will only work for the other classes if they too implement IEnumerable
A RepaskyRank #8,108 · 228 reputationPosted Jan 7, 2012, 2:13 PM EST
Arep
A RepaskyRank #8,108 · 228 reputationPosted Jan 11, 2012, 5:42 PM EST
I get these errors.
Error 2 Argument 1: cannot convert from 'MMOExtract.PHCRecord' to 'T' C:\MMOExtractClass\MMOExtract\MMOExtract\GenExcel.cs 221 23 MMOExtract
Error 4 Argument 1: cannot convert from 'MMOExtract.PHCSRecord' to 'T' C:\MMOExtractClass\MMOExtract\MMOExtract\GenExcel.cs 293 23 MMOExtract
Error 1 The best overloaded method match for 'System.Collections.Generic.List
Error 3 The best overloaded method match for 'System.Collections.Generic.List
On this:
listData.Add(phcsclass); What can I do to fix this. By the way, all of the record classes use IEnumerator. I am using this on another Method and it is working there. Thanks, ArepA RepaskyRank #8,108 · 228 reputationPosted Jan 14, 2012, 3:33 PM EST
That did it and it is all working. I thank you so much. You have been a great help.
Arep