C # for beginner part 55

Source: Internet
Author: User
Tags modifiers

Part # Tutorial Why Enums

Enums is strongly typed constants.

If a program uses set of integral numbers, consider replacing them with enums. Otherwise the Pragram becomes less

Readable maintainable

Part Tutorial C # Enums Example

public enum gender

{

Male

Female

}

Part Tutorial C # Enums in C #

1,enums is enumerations.

2,enums is strongly typed constants (constant). Hence (therefore), an explicit (explicit) cast is needed to convert the from enum type to an integral type and vice versa. Also, an enum of one TPE cannot is implicitly (implicit) assigned (designation) to an enum of another type even though the underlying Valu E of their members is the same.

3,the default underlying type of an enum is int.

4, the Defalut value for first element is ZERO and gets incremented (incremented) by 1.

5,it is possible to customize the underlying type and values.

6,enums is value types.

7,enum keyword (all small letteres) are used to create enumerations, where as Enum class,contains static GetValues () and Get Names () methods which can be used to list Enum underlying type values and Names.

Part Tutorial C # difference between Types and Type members

Part Tutorial C # Access Modifiers in C #

Part # Tutorial Internal and Protected Internal Access Modifiers in C #

Part Wuyi C # Tutorial Access Modifiers for types

Part Tutorial C # Attributes in C #

Part Tutorial C # Reflection in C #

Part Tutorial C # Reflection Example

Here is the code

private void Btndiscover_click (object sender, EventArgs e)
{
LbMethods.Items.Clear ();
LbProperties.Items.Clear ();
LbConstructor.Items.Clear ();
String typeName = TxtTypeName.Text.Trim ();
Type t = Type.GetType (typeName);
if (t = = null)
{
MessageBox.Show ("Type is No Exit, please Enter A right type!", "warnning", MessageBoxButtons . OK);
Txttypename.clear ();
Txttypename.focus ();
}
Else
{
Methodinfo[] methods = T.getmethods ();
Propertyinfo[] Properties = t.getproperties ();
Constructorinfo[] constructors = t.getconstructors ();
foreach (Var method in methods)
{
LbMethods.Items.Add (string. Concat (method. Returntype.name, "", Method. Name));
}
foreach (var property in properties)
{
LbProperties.Items.Add (string. Concat (property. Propertytype.name, "", property. Name));
}
foreach (Var constructor in constructors)
{
LbConstructor.Items.Add (constructor. ToString ());
}
}
}

Part Tutorial C # late binding using reflection

C # for beginner part 55

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.