Using struct in C #

2

I have to record customer information. And I used struct to do this. Is it worth doing this? Is it good practice or not?

    
asked by anonymous 02.06.2018 / 05:06

2 answers

3

Overall, no, this seems to be a clear case for a class, not only because of its size, but also because there is no identity in it. I've already given a answer that says when to pick one thing or another .

If you need a lot of performance and memory allocation control you can use yes, but you have to know what you're doing, it has several not-so-obvious implications, even for experienced programmers.

In C # 7.2 it has become easier to do this since you use readonly ref struct , but it still does not seem appropriate for your case, since it should allow direct writing to the object instead of creating a new one. If by chance the semantics is immutable, it can be useful, but not absolutely necessary. The simplest for a beginner will still be the use of the class.

    
02.06.2018 / 05:27
-1

Using class would be more appropriate / efficient. And Good Practice use Properties instead of fields. Note that in C # public properties begin with a capital letter.

public class Cliente 
{
   public string Email { set; get; }
   public string Telefone { set; get; }
   ...
}
    
02.06.2018 / 07:38