CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2011
    Posts
    3

    [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

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    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);
    }

  3. #3
    Join Date
    Mar 2011
    Posts
    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

  4. #4
    Join Date
    Aug 2005
    Posts
    198

    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());
    }
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com
    Instant C# - VB to C# Converter
    Instant VB - C# to VB Converter

  5. #5
    Join Date
    Mar 2011
    Posts
    3

    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
  •  





Click Here to Expand Forum to Full Width

Featured