What is main use of Enumeration?

后端 未结 10 1788
时光取名叫无心
时光取名叫无心 2020-12-08 07:35

What is main use of Enumeration in c#?

Edited:- suppose I want to compare the string variable with the any enumeration item then how i can do this

10条回答
  •  生来不讨喜
    2020-12-08 08:05

    Often you find you have something - data, a classification, whatever - which is best expressed as one of several discrete states which can be represented with integers. The classic example is months of the year. We would like the months of the year to be representable as both strings ("August 19, 2010") and as numbers ("8/19/2010"). Enum provides a concise way to assign names to a bunch of integers, so we can use simple loops through integers to move through months.

提交回复
热议问题