-3

I want to create a custom field in dot.net core which will have a bool as well as an integer or string value, something like the following:

Public MyCustomField field;
field.BoolValue = true or false;
field.NumberValue = 101;

Is this possible?

Max
  • 470
  • 2
  • 9
  • 22
  • You want a structure or class with multiple fields/properties of its own? Or a field/property you can assign a value of different types to? – Corey Jun 22 '23 at 00:53
  • What do you mean by Field ...in dot net you can create your custom types by many ways (classes, structs, Records) !! – Ibram Reda Jun 22 '23 at 01:43
  • There is no `Public` modifier in c#. Did you mean `public`? – Rufus L Jun 22 '23 at 01:52
  • @IbramReda There is a question here that will help you understand what a field is: https://stackoverflow.com/questions/653536/difference-between-property-and-field-in-c-sharp-3-0 – Rufus L Jun 22 '23 at 01:54
  • I need a field/property I can assign a value of different types to. – Max Jun 22 '23 at 06:36
  • @RufusL I already know the difference between properties and field, but the Way of Question is confusing me, anyway thanks for sharing I enjoy reading it, you are lighting me – Ibram Reda Jun 22 '23 at 13:15

1 Answers1

2

Yes, it is.

void Main()
{
    field.BoolValue = true;
    field.NumberValue = 101;
}

public MyCustomField field;

public struct MyCustomField // or `class`
{
    public bool BoolValue;
    public int NumberValue;
}
Enigmativity
  • 113,464
  • 11
  • 89
  • 172