Core C#

Enums with Assigned Values

This C# program demonstrates how to program with enums that have an assigned values in C#. By default, the first enumeration value is zero and each subsequent unassigned enumeration value is incremented by one from the previous value.

Program.cs

using System;

namespace Enumerations4 {

    enum EHttpStatus {
        keOk                    = 200,
        keBadRequest            = 400,
        keForbiddden            = 403,
        keNotFound              = 404,
        keInternalServerError   = 500
    }

    class Program {
        static void Main(string[] args) {
            foreach (EHttpStatus eStatus in Enum.GetValues(typeof(EHttpStatus))) {
                Console.WriteLine(String.Format("{0} has the value {1}", eStatus, (int)eStatus));
            }
        }
    }
}
 

Output

keOk has the value 200
keBadRequest has the value 400
keForbiddden has the value 403
keNotFound has the value 404
keInternalServerError has the value 500
Press any key to continue . . .
 
 

© 2007–2025 XoaX.net LLC. All rights reserved.