2009-03-17 7 views
-2
for (int z = 0; z < alParmValues.Count; z++) 
{ 
    asd.Add((alParmValues[z].ToString().Split(',')));// asd is list<string> 
    def.Add(alMethSign[z].ToString().Substring(alMethSign[z].ToString().IndexOf('(') + 1, alMethSign[z].ToString().IndexOf(')') - (alMethSign[z].ToString().IndexOf('(') + 1)).Split(','));// def is list<string> 
} 

Ce sont les erreurs que je reçois quand je compile:Comment puis-je corriger ces erreurs de compilation?

Error 7 The best overloaded method match for 'System.Collections.Generic.List<string>.Add(string)' has some invalid arguments 
    D:\HUTT\Code\HUTT\NUnitClasses\BaseGenerator.cs 1118 18 HUTT 
Error 8 Argument '1': cannot convert from 'string[]' to 'string' 
    D:\HUTT\Code\HUTT\NUnitClasses\BaseGenerator.cs 1118 27 HUTT 

Répondre

5

Le compilateur vous dit que vous ne pouvez pas utiliser la méthode List.Add() qui attend un string en entrée, parce que vous le remettre le retour de Split() qui retourne un string[]. Pour utiliser string[] comme entrée, utilisez AddRange().

4

Utilisation AddRange au lieu de Ajouter.

2

Essayez AddRange

0

String.Split retourne un tableau de chaînes (string []) mais List.Add attend un paramètre de type chaîne.

Questions connexes