About dataset, datatable, arraylist, ilist, array

Source: Internet
Author: User

Collect several types of knowledge points:

I. Relationship

Ilist IL = new arraylist ();

Ilist is an interface, which is inherited by javasraylist. Il is an arraylist object.

 

C # The format of the instance variable definition is
Static type variable name = instance;
If the static type is a class, the instance can be an Instance Object of the static type, or an instance object of its subclass.
If the static type is an interface, the instance can be an instance of its implementation class or an instance of its sub-interface implementation class.

Ilist IL = new arraylist ();
Is the second case 

Ii. Performance

When displaying data, the above objects are usually used as the carrier. Which of the following methods has better performance? Some people have provided the test method.

Test results.

Typeddatatable <datatable <arraylist <ilist <Array

Typeddatattable is nearly several times longer than datatalbe.

Arraylist is slower than ilist because of transformation.

When the length is determined, array is faster than ilist.

The performance of arraylist, ilist, and array is almost the same. We recommend that you use ilist.

 

 If (! Ispostback ){  /* **************************************** * ************************************ Declare @ I int -- variable @ I set @ I = 10 -- initialize @ I to 1 while @ I <100000000 -- If @ I is less than 100, change 1 million here to insert 1 million records begin ---------------- insert into price (name, provinceid) values the sale of 12 thousand nuclear fuel rods was shipped to foreign countries. The US claim North Korea agreed to sell 12 thousand nuclear fuel rods to foreign countries ', 1) set @ I = @ I + 1 end ------------------ set nocount on /************************** **************************************** ********* ******  */ Response. Buffer = True  ; Response. Expires = 0  ; Response. expiresabsolute = Datetime. Now. adddays (- 1  ); Response. addheader (  "  Pragma  " , "  No-Cache  " ); Response. addheader (  "  Cache-control  " , "  Private  "  ); Response. cachecontrol = "  No-Cache  "  ;  Int I = 0 ; Sqlconnection CN = New  Sqlconnection (DAL. dbhelper. connectionstring); sqlcommand cm = New Sqlcommand ( "  Select * from test  "  , CN); CN. open (); sqldatareader RDR = Cm. executereader ();  While  (RDR. Read () {I ++;} RDR. Close (); CN. Close (); sqldataadapter ADA = Null  ; Response. Write (  "  Start... <br> <Table border = \ "1 \" cellpadding = \ "2 \" cellspacing = \ "1 \">  "  ); Datetime start; datetime end; timespan [] TS = New Timespan [ 5  ];  // For (INT counter = 1; counter< = 100; counter ++)  //  { Start = Datetime. now;  For ( Int Smallcounter = 1 ; Smallcounter <= 1 ; Smallcounter ++ ) {ADA = New Sqldataadapter ( "  Select * from test "  , CN); dataset DS = New  Dataset (); CN. open (); Ada. Fill (DS); CN. Close ();} End = Datetime. Now; TS [  0 ] + = End- Start; response. Write (  "  <Tr style = 'height: 20px; '> <TD> Dataset: </TD> <TD style = 'width: 100px;'>  " + Convert. tostring (end-Start) +"  </TD> </tr>  "  ); Start = Datetime. now;  For ( Int Smallcounter = 1 ; Smallcounter <= 1 ; Smallcounter ++ ) {Cm = New Sqlcommand ( " Select * from test  "  , CN); ilist <Dal. tts_pai_price> mylist = New List <Dal. tts_0000_price> (); CN. open (); RDR = Cm. executereader ();  While  (RDR. Read ()){  //  New DAL. tts_pai_price (RDR. getint64 (0), RDR. getint64 (1), RDR. getstring (2 )) Mylist. Add (New  Dal. tts_hotel_price ();} RDR. Close (); CN. Close ();} End = Datetime. Now; TS [  1 ] + = End- Start; response. Write (  "  <Tr> <TD> ilist: </TD> <TD>  " + Convert. tostring (end-Start) + "  </TD> </tr>  " ); Start = Datetime. now;  For ( Int Smallcounter = 1 ; Smallcounter <= 1 ; Smallcounter ++ ) {Cm = New Sqlcommand ( "  Select * from test  "  , CN); arraylist myal =New  Arraylist (); CN. open (); RDR = Cm. executereader ();  While  (RDR. Read ()){  //  New DAL. tts_pai_price (RDR. getint64 (0), RDR. getint64 (1), RDR. getstring (2 ))  Myal. Add (RDR);} RDR. Close (); CN. Close ();} End = Datetime. Now; TS [ 2 ] + = End- Start; response. Write (  "  <Tr> <TD> arraylist: </TD> <TD>  " + Convert. tostring (end-Start) + "  </TD> </tr>  "  ); Start = Datetime. now;  For ( Int Smallcounter = 1 ; Smallcounter <= 1 ; Smallcounter ++ ) {Cm = New Sqlcommand ( "  Select * from test  "  , CN); Dal. tts_1__price [] myarray = New Dal. tts_pai_price [ 200800  ]; CN. open ();  Int Flag =0  ; RDR = Cm. executereader ();  While  (RDR. Read () {myarray [flag] = New Dal. tts_pai_price (); //  New DAL. tts_pai_price (RDR. getint64 (0), RDR. getint64 (1), RDR. getstring (2 )); Flag ++ ;} RDR. Close (); CN. Close ();} End =Datetime. Now; TS [  3 ] + = End- Start; response. Write (  "  <Tr> <TD> []: </TD> <TD>  " + Convert. tostring (end-Start) + "  </TD> </tr>  "  ); Start = Datetime. now;  For ( Int Smallcounter = 1 ; Smallcounter <= 1 ; Smallcounter ++ ) {ADA = New Sqldataadapter ( "  Select * from test  "  , CN); datatable atable = New  Datatable (); CN. open (); Ada. Fill (atable); CN. Close ();} End =Datetime. Now; TS [  4 ] + = End- Start; response. Write (  "  <Tr> <TD> datatable: </TD> <TD>  " + Convert. tostring (end-Start) + "  </TD> </tr>  "  ); Response. Write (  "  </Table> <br> end ............  " );  //  Foreach (timespan ts in ts)  //  {  //  Response. Write ("<br>" + TS );  //  } }

 

 

 

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.