Here is what I have:
How do you pass List
class ProcessClaims
{
public static List<MMORecord> listDataMMO = new List<MMORecord>();
public static List<PHCSRecord> listDataPHCS = new List<PHCSRecord>();
public static List<PHCRecord> listDataPHC = new List<PHCRecord>();public static List<MMORecord> listDataPHS = new List<MMORecord>();
public static List<MMORecord> listDataGLB = new List<MMORecord>();
public static List<PHCRecord> listDataNotcovered = new List<PHCRecord>();
public static List<MMORecord> listDataDEL = new List<MMORecord>();
public static List<PHCRecord> listDataMC1 = new List<PHCRecord>();
public static List<MMORecord> listDataHC = new List<MMORecord>();
public static List<PHCSRecord> listDataMultiplan = new List<PHCSRecord>();
The MMORecord, PHCSRecord, PHCRecord are classes.
Then I use it to pass to a Method.
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,
List<string> header, List<PHCSRecord> listData, List<int> setNumber)
How can I pass this Listso 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 Listwhich 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
VulpesPosted Jan 12, 2012, 6:25 AM
A RepaskyPosted Jan 14, 2012, 8:33 PM
That did it and it is all working. I thank you so much. You have been a great help.
Arep
A RepaskyPosted Jan 11, 2012, 10:42 PM
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:
A RepaskyPosted Jan 7, 2012, 7:13 PM
Arep
VulpesPosted Jan 7, 2012, 2:19 PM
Even if it now works OK for the PHCSRecord class, it will only work for the other classes if they too implement IEnumerable
A RepaskyPosted Jan 7, 2012, 12:22 PM
> 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
A RepaskyPosted Jan 6, 2012, 5:17 PM
I have to leave now and will work over the weekend. Go to game tonight though.
Arep
VulpesPosted Jan 6, 2012, 5:13 PM
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 RepaskyPosted Jan 6, 2012, 5:05 PM
>. So I am going that way.
Thanks,
Arep
VulpesPosted Jan 6, 2012, 11:12 AM
To use them generically, they either need to implement some common interfaces or inherit from a common base class.
A RepaskyPosted Jan 6, 2012, 11:07 AM
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
VulpesPosted Jan 6, 2012, 10:57 AM
A RepaskyPosted Jan 6, 2012, 10:26 AM
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:
VulpesPosted Jan 6, 2012, 10:08 AM