Example code for how type parameters are generated when you create a new DataColumn class in C #

Source: Internet
Author: User

A

few of the DataColumn classes require the constructor of the type parameter as follows:

        Summary: Initializes a new instance of the System.Data.DataColumn class with the specified column name and data type. Parameters://ColumnName://A String that represents the name of the column to be created.        If set to null or an empty string (""), a default name is specified when added to the column collection.        DataType://Supported System.Data.DataColumn.DataType.        Exception://System.ArgumentNullException://No DataType specified.        Public DataColumn (String columnName, Type dataType);        Summary: Initializes a new instance of the System.Data.DataColumn class with the specified name, data type, and expression. Parameters://ColumnName://A String that represents the name of the column to be created.        If set to null or an empty string (""), a default name is specified when added to the column collection.        DataType://Supported System.Data.DataColumn.DataType. Expr://The expression used to create the column.        For more information, see System.Data.DataColumn.Expression Properties.        Exception://System.ArgumentNullException://No DataType specified. Public DataColumn (String columnName, Type DataType,string expr);        Summary: Initializes a new instance of the System.Data.DataColumn class with the specified name, data type, expression, and value that determines whether the column is a property. Parameters://ColumnName://A String that represents the name of the column to be created.        If set to null or an empty string (""), a default name is specified when added to the column collection.        DataType://Supported System.Data.DataColumn.DataType. Expr://The expression used to create the column.        For more information, see System.Data.DataColumn.Expression Properties.        Type://System.Data.MappingType one of the values.        Exception://System.ArgumentNullException://No DataType specified. Public DataColumn (String columnName, type DataType, string expr, MappingType type);

Several statements in C # that are related to types type

1, typeof
typeof is an operator, typeof (type). such as typeof (BOOL), typeof (int), typeof (System.Windows.Forms.TextBox)
2, Type.GetType (type name). This type name is String, quoted.
3, Object.GetType (). A member of the object class that has this method for C # class objects.
All 3 of the above return to System.Type.

Specific Use examples:

        private void Form1_Load (object sender, EventArgs e) {try {dt = new D                Atatable (); Dt.                 Columns.Add (New DataColumn ("One", System.Type.GetType ("System.Double")); System.Type.GetType (TypeCode.Double.ToString ()) cannot be used with DT in this way.                Columns.Add (New DataColumn ("A", System.Type.GetType ("System.Double")); Dt.                Columns.Add (New DataColumn ("three", typeof (Double))); Dt. Columns.Add (New DataColumn ("Four", (1D).                GetType ()));                Random rnd = new Random (); for (int i = 0; i <; i++) {dt. Rows.Add (New object[] {(Double) rnd. Next (1, 234923745), (Double) Rnd. Next (1, 234923745), (Double) Rnd. Next (1, 234923745), (Double) Rnd.                Next (1, 234923745)}); } dt.                Defaultview.sort = "one asc,two ASC"; Datagridview1.datasource = dt.            DefaultView; } catch (SYstem. Exception ex) {MessageBox.Show (ex.            Message); }        }
Related Article

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.