Skip to main content

Posts

Showing posts with the label enumeration

enum in kotlin

ENUM Enums help us in defining like a fixed key-value pairs and then use them. These are to be used like fixed pairs and need not be stored in database or be something that shows up dynamically. These are mostly fixed entries. enum class ProductCategories ( val cat : String , val id : Int ) { ELECTRONICS ( "Electronics" , 0), ACCESSORIES ( cat = "Computer Accessories" , 1), PHERIPHERALS ( cat = "Computer Pheripherals" , id = 2); //This is a mandatory semi-colon fun getEnumId () = id fun categoryName () = cat } fun main (){ println ( ProductCategories . ACCESSORIES .categoryName()) println ( ProductCategories . PHERIPHERALS .categoryName()) }

Handling Enumerations in C# as Strings

In Order for an Enumeration in C# to be processed as a string, use the string formats described below, Sample: enum Colors {Red, Green, Blue, Yellow = 12}; Colors myColor = Colors.Yellow; myColor.ToString("g") = Yellow myColor.ToString("G") = Yellow myColor.ToString("x") = 0000000C myColor.ToString("X") = 0000000C myColor.ToString("d") = 12 myColor.ToString("D") = 12 myColor.ToString("f") = Yellow myColor.ToString("F") = Yellow As shown in the above samples, the following format specifiers :   g,G,x,X,d,D,f and F are used to convert a integer based enum value to string format. -- Saravanan