Enumerators in C# .Net

Ratings:
(4)
Views:804
Banner-Img
  • Share this blog:

 

Enumerators (enum)

enum is a keyword enum is a collection of integral Constant's, which will be Identified with string constants. enum is a user-defined data type.

Syntax to write enum  

Enum enum _name

{

String value =  Integer value,

String value =  Integer value,

String value =  Integer value,

}

enum must be declared in general declaration (Go) area only.  

Interested in mastering .NET? Learn more about ".NET Training" in this blog post.

C language

Int  k = 10;

arrrowglobal variable Main () { Int I = 10;

arrrow local variable }syntax of form1 code window Using system  Using system.data Namespace ABC  

arrrowproject name    } } }

Note  For every project by default a name space will be created with the name of the project. Using is a keyword which is used to import the namespace (collection of classes )

Example 1 on Enum 

arrrow Open windows form application project

arrrowPlace a button

arrrowCode for  GD  (general declaration)

  Screenshot_38  

Code for button 1

click {

Int  I, j, k;

I = (int) GTB. Sa;

j = (int) GTB. Ja;

k = (int) GTB. Ca;

  Message Box. Show (I + “” + j + “” + k);

}

Execute the project  

Observations

When enum member is not initialized then it will be initialized automatically with the incremented value of the previous member.

In case the previous member is not existing then initialization starts from “ZERO”  

Example:-

A program for developing the animated label.

To develop this application buttons, labels, and timer controls are required.  

About Label

Generally, a label is used to display some text along with an image [optional]. Label control supports nine types of alignments.

   To manage all these alignments, Microsoft introduced a predefined e num called as content alignment.

  Screenshot_40

About Timer Control

The timer control is used to execute a set of statements continuously provided a property called Enabled must be true. Enabled  = true (false)

 Timer tick event will be executed after the equal interval which needs to be specified in milliseconds   (1000 ms = 1 sec)

  Open windows forms application project Place a button

arrrowproperties  F4

 arrrowtext = start  

arrrowPlace one more button

 arrrowproperties

arrrowtext   = start Place a label control

arrrowproperties text  = fish land text Align  = middle center Auto size = false Image = select an image Place a timer contro

lScreenshot_41

 

Code in GD (Before Button 1 click)

 Int I = 0; Int [] x = new int [] 

{

(int) content Alignment ,

Top center, (int) content Alignment . Middle Right,

(int) content Alignment. Bottom center,

(int) content Alignment. Middle left

};

Code for Timer 1

tick (double click on timer)

{ I = I +1; If (I = =4) I =0;  

Label 1. Image Align  = (Content Alignment) X [i];

}

Code for Button 1_ click (Start)

{
Timer 1 .enabled = true;
}

Code for button 2_click (stop)

{

Timer1.enabled = false;

}

You liked the article?

Like : 0

Vote for difficulty

Current difficulty (Avg): Medium

Recommended Courses

1/15

About Author
Authorlogo
Name
TekSlate
Author Bio

TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.


Stay Updated


Get stories of change makers and innovators from the startup ecosystem in your inbox