Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to prevent possible error in this code?
Message
 
 
To
All
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
How to prevent possible error in this code?
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01599006
Message ID:
01599006
Views:
46
Hi everybody,

I am writing this code:
 for (Int16 i = 1; i <= 6; i++ )
                {
                    insertCommand.Parameters.Add(String.Format("@pr_ctr_{0}", i), SqlDbType.Int).Value = drItem.Field<Int32>(String.Format("pr_ctr_{0}", i));

                    insertCommand.Parameters.Add(String.Format("@PC{0}Amt", i), SqlDbType.Money).Value =  splitAmounts[i-1] ;
                }
splitAmounts variable defined as
List<Decimal>
I want to prevent possibility of that list having less than 6 elements, so in this case I would assign 0 to my parameter. Is there a way to do it in one line (change the last line) or I should add an extra if to check
i-1 < splitAmounts.Count
?

I guess I can use IIF C# analogue here.
If it's not broken, fix it until it is.


My Blog
Next
Reply
Map
View

Click here to load this message in the networking platform