简体   繁体   English

调试System.FormatException

[英]Debugging a System.FormatException

"Index (zero based) must be greater than or equal to zero and less than the size of the argument list." “索引(从零开始)必须大于或等于零且小于参数列表的大小。”
("Der Index, basierend auf 0 (null), muss größer als oder gleich Null sein, und kleiner als die Größe der Argumentenliste.") (“ Der Index,basierend auf 0(空),mussgrößerals oder gleich Null sein,和kleiner als dieGrößeder Argumentenliste。”)

when executing the line: 执行该行时:

search.Filter = string.Format(filter,filterparams);

where, at runtime, filter contains "(sAMAccountName={0})(sAMAccountName={1})" and filterparams is a StringList with the two member strings "Testuser" and "Vertrieb". 其中,在运行时, filter包含"(sAMAccountName={0})(sAMAccountName={1})"filterparams是具有两个成员字符串“ Testuser”和“ Vertrieb”的StringList。

What exactly is the error message trying to tell me? 错误消息试图告诉我的是什么?

The error says that there are more tokens in the format string than in the argument list. 该错误表明格式字符串中的令牌比参数列表中的令牌更多。 The second parameter of String.Format is an array of objects (from MSDN): String.Format的第二个参数是对象数组(来自MSDN):

public static string Format(
    string format,
    params object[] args
)

The StringList is not implicitly converted to an array of objects so that String.Format interprets the StringList as one argument - hence the error. StringList不会隐式转换为对象数组,因此String.Format会将StringList解释为一个参数-因此是错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM