1

Possible Duplicate:
Struct v/s Class in C# - Please explain the behavior.

I am confused that have seen often that we create custom object by following

public class Student { public string Name{get;set;} public string Class{get;set;} public string Section{get;set;} } 

and create instant and use its attributes as property for example

List<Student> absentUsers = new List<Students>(); Student studenttoadd = new Student();//Object studenttoadd.Name = "You"; studenttoadd.Class = "PlayGroup"; absentUsers.Add(studenttoadd); 

and so on

but isn't it true that we can do same with Struct?

What is mentioned approach called(example i have given)?

When to Use this approach and when to use struct?

is there any performance /memory allocation difference?

4
  • 2
    See the following answers: stackoverflow.com/questions/5620843/…, stackoverflow.com/questions/5456463/… Commented Jun 7, 2011 at 15:50
  • @Cody: I started to write an answer and realized that 'Struct vs. Class' has been repeated many times. Commented Jun 7, 2011 at 15:55
  • It would be a huge mistake to use struct here. A common mistake for people from C++ etc, but a mistake. Commented Jun 7, 2011 at 15:57
  • so basically when would you prefer struct over this approach Commented Jun 7, 2011 at 16:17

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.