|
-
March 17th, 2011, 02:35 PM
#1
[RESOLVED] List in a List - VB Conversion to C#
There is not .ToList() method available with a direct conversion.
Code:
///VB Code
lds.Fields = fs.FieldAliases.Keys.ToList
lds.Values = New List(Of List(Of Object))
For i As Integer = 0 To fs.Features.Count - 1
lds.Values.Add(fs.Features.Item(i).Attributes.Values.ToList)
Next
/////
This is what I am trying…not working.
Code:
///C# Conversion
foreach (string xyz in fs.FieldAliases.Keys)
{
lds.Fields.Add(xyz);
}
lds.Values = new List<List<Object>>();
List<object> lstValues = new List<object>();
lstValues = new List<Object>();
for (int i = 0; (i
<= (fs.Features.Count - 1)); i++)
{
foreach (object o in fs.Features)
{
lstValues.Add(o);
}
lds.Values.Add(lstValues);
}
Keith
-
March 17th, 2011, 02:49 PM
#2
Re: List in a List - VB Conversion to C#
Try
Code:
foreach (string xyz in fs.FieldAliases.Keys)
{
lds.Fields.Add(xyz);
}
lds.Values = new List<List<Object>>();
for (int i = 0; i < fs.Features.Count; i++)
{
var lstValues = new List<Object>();
lstValues.AddRange( fs.Features );
lds.Values.Add(lstValues);
}
-
March 17th, 2011, 03:28 PM
#3
Re: List in a List - VB Conversion to C#
Thank You Arjay!
I will study up on .AddRange
Someone also suggested using System.Linq so .ToList would run as in VB.
Thansk again for the quick turnaround.
Keith
-
March 17th, 2011, 06:23 PM
#4
Re: [RESOLVED] List in a List - VB Conversion to C#
ToList is also available in C# - it's just that VB allowed you to drop the empty argument list:
Code:
lds.Fields = fs.FieldAliases.Keys.ToList();
lds.Values = new List<List<object>>();
for (int i = 0; i < fs.Features.Count; i++)
{
lds.Values.Add(fs.Features[i].Attributes.Values.ToList());
}
-
March 18th, 2011, 08:28 AM
#5
Re: [RESOLVED] List in a List - VB Conversion to C#
Thanks David....
Try your solution without using System.Linq;
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|