0

Is there a type like enum that would allow me to merge these variable into one

    private string StringPropertie;
    private int IntPropertie;
    private float floatPropertie;
    private DateTime DatetimePropertie;
    private bool boolPropertie;

to something has follow.

private enumtype property
Jseb
  • 1,926
  • 4
  • 29
  • 51

1 Answers1

1

You can use structure

public struct MyStruct
    {
        public string StringPropertie;
        public int IntPropertie;
        public float floatPropertie;
        public DateTime DatetimePropertie;
        public bool boolPropertie;
    }

    public class MyClass
    {
        public MyClass()
        {
              MyStruct property ;
              //...


              string str = property.StringPropertie;

        }
   }
  • how would it know to choose between int and string – Jseb Oct 16 '15 at 01:01
  • @Jseb that's part of the editor & compiler, not yours. – King King Oct 16 '15 at 01:04
  • Don't use mutable structs! A `class` is better suited if you feel that you need a mutable data type. – Ron Beyer Oct 16 '15 at 01:34
  • @Ron Beyer It is up to the user to see what he needs. Sometimes a class, and sometimes a structure. With the difference that we know between these two entities. a structure may be stacked so that a class is not. –  Oct 16 '15 at 01:40
  • Mutable structs are almost always a bad idea, see http://stackoverflow.com/questions/441309/why-are-mutable-structs-evil and https://msdn.microsoft.com/en-us/library/ms229031(v=vs.110).aspx where even Microsoft says to avoid mutable structs. – Ron Beyer Oct 16 '15 at 01:43
  • @AtmaneELBOUACHRI If the OP is at the level of asking how to define a class/struct, it's almost certain they should be using class. – Rob Oct 16 '15 at 02:20