• USA : +1 973 910 5725
  • INDIA: +91 905 291 3388
  • info@tekslate.com
  • Login

Enumerators in C# .Net

Enumerators (enum)

enum is a keyword

enum is a collection of integral Constants , 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.

 

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

 

Screenshot_37

 

}

}

}

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 )

 

Ex ample 1 on Enum 

arrrow Open windows forms 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 incremented value of previous member.

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

 

Example :- A program for developing animated label

 

Screenshot_39

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

 

About Label

Generally label is used to display some text a long with an image [optional].

Label control supports nine types of alignments.

Screenshot_40

 

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

 

About Timer Control

Timer control is used to execute a set of statements continuously provided a property called as Enabled must be true.

Enabled  = true (flase)

Screenshot_41

Timer tick event will be executed after equal interval which need 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 control

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;

}

“At TekSlate, we are trying to create high quality tutorials and articles, if you think any information is incorrect or want to add anything to the article, please feel free to get in touch with us at info@tekslate.com, we will update the article in 24 hours.”

0 Responses on Enumerators in C# .Net"

Leave a Message

Your email address will not be published. Required fields are marked *

Site Disclaimer, Copyright © 2016 - All Rights Reserved.