About the arraylist class

Source: Internet
Author: User
Parameters of the arraylist class are involved in the following method:
/// <Summary>
/// Execute multiple SQL statements to implement database transactions.
/// </Summary>
/// <Param name = "sqlstringlist"> Multiple SQL statements </param>
Public static void executesqltran ( Arraylist sqlstringlist ) // Use the size of the array that can be automatically added as needed to load parameters
{
Using (sqlconnection conn = new sqlconnection (connectionstring ))
{
Conn. open ();
Sqlcommand cmd = new sqlcommand ();
Cmd. Connection = conn;
Sqltransaction Tx = conn. begintransaction (); // starts database transactions at the specified isolation level and transaction name
Cmd. Transaction = TX; // obtain or set sqltransaction (TRANSACT-SQL transaction) for the sqlcommand object to be executed)
Try
{
For (INT n = 0; n <sqlstringlist. Count; n ++)
{
String strsql = sqlstringlist [N]. tostring ();
If (strsql. Trim (). length> 1)
{
Cmd. commandtext = strsql;
Cmd. executenonquery (); // traverse to execute the SQL statement in the dynamic array
}
}
TX. Commit (); // submit database transactions
}
Catch (system. Data. sqlclient. sqlexception E)
{
TX. rollback (); // roll back the transaction from the pending state, and specify the transaction or save point name
Throw new exception (E. Message );
}
}
}

What is the difference between the arraylist class and the array class? arraylist is a complex version of the array class. The arraylist class provides some functions that are provided in most collections classes but not in the array class. The main points are as follows: 1. array is located in the system namespace, while arraylist is located in the system. Collections namespace. 2. the array capacity is fixed, and the arraylist capacity is automatically expanded as needed. If the value of the arraylist. Capacity attribute is changed, the memory quota element is automatically replicated. 3. arraylist provides a method to add, insert, or remove a range of elements. In array, only one element value can be obtained or set at a time. 4. Use synchronized to easily create a synchronization version of arraylist. Array will keep it until the user achieves synchronization. 5. arraylist provides a method to return read-only and fixed-size packages to a set, but array does not. 6. On the other hand, array provides some flexibility that arraylist does not have. 7. You can set the lower limit of array, but the lower limit of arraylist is always zero. 8. array can have multiple dimensions, while arraylist is always only one-dimensional 9. Specific types of arrays have better performance than arraylist because the elements of arraylist belong to the object type, therefore, boxing and unboxing are often generated when you store or retrieve value types.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.