Skip to main content
formatting
Source Link
svick
  • 24.3k
  • 4
  • 52
  • 89

This MSDN Page states:

CONSIDER defining a struct instead of a class

  • if instances of the type are small and commonly short-lived or are commonly embedded in other objects.

AVOID defining a struct unless the type has all of the following characteristics:

  • It logically represents a single value, similar to primitive types (int, double, etc.).
  • if instances of the type are small and commonly short-lived or are commonly embedded in other objects.
    AVOID defining a struct unless the type has all of the following characteristics:
  • It logically represents a single value, similar to primitive types (int, double, etc.).
  • It has an instance size under 16 bytes.
  • It is immutable.
  • It will not have to be boxed frequently.

So if you want to use a class instead of a structure, you can just add the same static goofy method, to get the same style like you get with the structure:

   public static retclass goofie(int isn, string ss)
    {
        retclass dex = new retclass();
        dex.str = ss;
        dex.num = isn;
        if ((dex.str != "") && (dex.num > 0))
        {
            dex.yesno = true;
        }
        return dex;
    }

You can either add this to the Main or better inside the class itself. If you consider the second, you can call it like:

retclass x = retclass.goofie(3, "this is the reclass string");

Console.WriteLine("The String is {0}, the int is {1} and the value 
      is {2}", x.str, x.num, x.yesno);

This MSDN Page states:

CONSIDER defining a struct instead of a class

  • if instances of the type are small and commonly short-lived or are commonly embedded in other objects.
    AVOID defining a struct unless the type has all of the following characteristics:
  • It logically represents a single value, similar to primitive types (int, double, etc.).
  • It has an instance size under 16 bytes.
  • It is immutable.
  • It will not have to be boxed frequently.

So if you want to use a class instead of a structure, you can just add the same static goofy method, to get the same style like you get with the structure:

   public static retclass goofie(int isn, string ss)
    {
        retclass dex = new retclass();
        dex.str = ss;
        dex.num = isn;
        if ((dex.str != "") && (dex.num > 0))
        {
            dex.yesno = true;
        }
        return dex;
    }

You can either add this to the Main or better inside the class itself. If you consider the second, you can call it like:

retclass x = retclass.goofie(3, "this is the reclass string");

Console.WriteLine("The String is {0}, the int is {1} and the value 
      is {2}", x.str, x.num, x.yesno);

This MSDN Page states:

CONSIDER defining a struct instead of a class

  • if instances of the type are small and commonly short-lived or are commonly embedded in other objects.

AVOID defining a struct unless the type has all of the following characteristics:

  • It logically represents a single value, similar to primitive types (int, double, etc.).
  • It has an instance size under 16 bytes.
  • It is immutable.
  • It will not have to be boxed frequently.

So if you want to use a class instead of a structure, you can just add the same static goofy method, to get the same style like you get with the structure:

   public static retclass goofie(int isn, string ss)
    {
        retclass dex = new retclass();
        dex.str = ss;
        dex.num = isn;
        if ((dex.str != "") && (dex.num > 0))
        {
            dex.yesno = true;
        }
        return dex;
    }

You can either add this to the Main or better inside the class itself. If you consider the second, you can call it like:

retclass x = retclass.goofie(3, "this is the reclass string");

Console.WriteLine("The String is {0}, the int is {1} and the value 
      is {2}", x.str, x.num, x.yesno);
added 13 characters in body
Source Link
Heslacher
  • 50.4k
  • 5
  • 81
  • 175

This MSDN Page states:

CONSIDER defining a struct instead of a class

  • if instances of the type are small and commonly short-lived or are commonly embedded in other objects.
    AVOID defining a struct unless the type has all of the following characteristics:
  • It logically represents a single value, similar to primitive types (int, double, etc.).
  • It has an instance size under 16 bytes.
  • It is immutable.
  • It will not have to be boxed frequently.

So if you want to use a class instead of a structure, you can just add the same static goofy method, to get the same style like you get with the structure:

   public static retclass goofie(int isn, string ss)
    {
        retclass dex = new retclass();
        dex.str = ss;
        dex.num = isn;
        if ((dex.str != "") && (dex.num > 0))
        {
            dex.yesno = true;
        }
        return dex;
    }

You can either add this to the Main or better inside the class itself. If you consider the second, you can call it like:

retclass x = retclass.goofie(3, "this is the reclass string");

Console.WriteLine("The String is {0}, the int is {1} and the value 
      is {2}", x.str, x.num, x.yesno);

This MSDN Page states:

CONSIDER defining a struct instead of a class

  • if instances of the type are small and commonly short-lived or are commonly embedded in other objects.
    AVOID defining a struct unless the type has all of the following characteristics:
  • It logically represents a single value, similar to primitive types (int, double, etc.).
  • It has an instance size under 16 bytes.
  • It is immutable.
  • It will not have to be boxed frequently.

So if you want to use a class instead of a structure, you can just add the same static goofy method, to get the same style like the structure:

   public static retclass goofie(int isn, string ss)
    {
        retclass dex = new retclass();
        dex.str = ss;
        dex.num = isn;
        if ((dex.str != "") && (dex.num > 0))
        {
            dex.yesno = true;
        }
        return dex;
    }

You can either add this to the Main or better inside the class itself. If you consider the second, you can call it like:

retclass x = retclass.goofie(3, "this is the reclass string");

Console.WriteLine("The String is {0}, the int is {1} and the value 
      is {2}", x.str, x.num, x.yesno);

This MSDN Page states:

CONSIDER defining a struct instead of a class

  • if instances of the type are small and commonly short-lived or are commonly embedded in other objects.
    AVOID defining a struct unless the type has all of the following characteristics:
  • It logically represents a single value, similar to primitive types (int, double, etc.).
  • It has an instance size under 16 bytes.
  • It is immutable.
  • It will not have to be boxed frequently.

So if you want to use a class instead of a structure, you can just add the same static goofy method, to get the same style like you get with the structure:

   public static retclass goofie(int isn, string ss)
    {
        retclass dex = new retclass();
        dex.str = ss;
        dex.num = isn;
        if ((dex.str != "") && (dex.num > 0))
        {
            dex.yesno = true;
        }
        return dex;
    }

You can either add this to the Main or better inside the class itself. If you consider the second, you can call it like:

retclass x = retclass.goofie(3, "this is the reclass string");

Console.WriteLine("The String is {0}, the int is {1} and the value 
      is {2}", x.str, x.num, x.yesno);
Source Link
Heslacher
  • 50.4k
  • 5
  • 81
  • 175

This MSDN Page states:

CONSIDER defining a struct instead of a class

  • if instances of the type are small and commonly short-lived or are commonly embedded in other objects.
    AVOID defining a struct unless the type has all of the following characteristics:
  • It logically represents a single value, similar to primitive types (int, double, etc.).
  • It has an instance size under 16 bytes.
  • It is immutable.
  • It will not have to be boxed frequently.

So if you want to use a class instead of a structure, you can just add the same static goofy method, to get the same style like the structure:

   public static retclass goofie(int isn, string ss)
    {
        retclass dex = new retclass();
        dex.str = ss;
        dex.num = isn;
        if ((dex.str != "") && (dex.num > 0))
        {
            dex.yesno = true;
        }
        return dex;
    }

You can either add this to the Main or better inside the class itself. If you consider the second, you can call it like:

retclass x = retclass.goofie(3, "this is the reclass string");

Console.WriteLine("The String is {0}, the int is {1} and the value 
      is {2}", x.str, x.num, x.yesno);