0
我使用下面的代碼來構建一個固定長度的文本文件。指數超出界限。 string.format可以保存多少個索引項?
TestFile.WriteLine(string.Format(
//Formats with negative numbers are left justified. e.g. {1,-10}
"{0,50}" + //SPACER 50
"{1,-10}" + //NCSBN ID
"{2,10}" + //SPACER 10
"{3,-50}" + //LAST NAME
"{4,-30}" + //FIRST NAME
"{5,-30}" + //MIDDLE NAME
"{6,90}" + //SPACER 90
"{7,-8}" + //DOB
"{8,-1}" + //GENDER
"{9,-9}" + //SOCIAL SECURITY NUMBER
"{10,41}" + //SPACER 41
"{11,-60}" + //ADDRESS 1
"{12,-60}", //ADDRESS 2
DbReader.GetString(0),DbReader.GetString(1),DbReader.GetString(2),
DbReader.GetString(3), DbReader.GetString(4),DbReader.GetString(5),
DbReader.GetString(6), DbReader.GetString(7), DbReader.GetString(8),
DbReader.GetString(9), DbReader.GetString(10), DbReader.GetString(11),
DbReader.GetString(12)));
一切都很好,直到我加入12指數則出現以下錯誤:
System.IndexOutOfRangeException was unhandled
Message="Index was outside the bounds of the array."
Source="System.Data"
StackTrace:
at System.Data.Odbc.DbCache.AccessIndex(Int32 i)
at System.Data.Odbc.OdbcDataReader.internalGetString(Int32 i)
at System.Data.Odbc.OdbcDataReader.GetString(Int32 i)
at BuildFile_EXE.Program.Main(String[] args) in G:\IT Development\SSIS\Reports\NursysAPRN_ToNatCouncil\BuildFile_EXE\BuildFile_EXE\Program.cs:line 69
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
是否具有的String.Format 11指數的限制還是我失去了一些東西明顯?
謝謝。
謝謝。我對編程還很陌生,有時會發現很難理解我得到的一些錯誤消息。 – kdejarnet