WebFeb 8, 2024 · public readonly List myConsts = typeof (Permissions) .GetFields () .Select (x => x.GetValue (null).ToString ()) .ToList (); This looks at the Permissions type, selects all public fields, then pulls the values from those FieldInfo into a new collection. Share Improve this answer Follow answered Feb 8, 2024 at 23:42 David L 32.4k 8 63 93 WebJun 22, 2024 · In C#, use readonly to declare a const array. public static readonly string [] a = { "Car", "Motorbike", "Cab" }; In readonly, you can set the value at runtime as well …
C# array of const string - Stack Overflow
Webinternal static class ErrorMessage { public const string NoAccess = "Error accessing api - check internet connection/api address"; } And you can reference that by using : result = new TextResult (ErrorMessage.NoAccess); Or, you can use a resource file. Share Improve this answer Follow answered May 4, 2016 at 18:08 Xiaoy312 14.2k 1 32 43 WebJun 5, 2024 · select new SelectListItem { Text = (string)na.TypedValue.Value, Value = (string)f.GetRawConstantValue () }; var list = selectLisItems.ToList (); At last I'm constructing SelectListItem from the attribute and the fields and create the desired List from the query. enbridge crossing application
c# - How can I get all constants of a type by reflection? - Stack Overflow
WebJan 22, 2024 · To give you a quick example of the numerous ( 20 in total) const ants that are defined in the class: private const string NAME1 = "NAME1"; private const string NAME2 = "NAME2"; private const string NAME3 = "NAME3"; ... As you can see, the name of the constant equals the value of it, if that can help. WebDepending on your context, there might be some solutions, one of them is, if what you really need is a list of double, List a = new List () {1,2,3,4,5}.AsReadOnly (); will give you a content-readonly list of double. The problem is that you're declaring a constant array of double, not an array of constant doubles. enbridge credit card payments