![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi, When to use class and when structure in our application? |
I almost
#3
| |||
| |||
|
|
Hi, When to use class and when structure in our application? Thanks, Bhuwan |
#4
| |||
| |||
|
|
Hi, When to use class and when structure in our application? Thanks, Bhuwan |
#5
| |||
| |||
|
|
Thanks all Bhuwan "Bhuwan Bhaskar" <kxxx (AT) gmail (DOT) com> wrote in message news:eyO5O1eFIHA.4752 (AT) TK2MSFTNGP04 (DOT) phx.gbl... Hi, When to use class and when structure in our application? Thanks, Bhuwan |
#6
| |||
| |||
|
|
Another consideration is that a class is a reference type while a structure is a value type. So, if you want to create copies of instances instead of references when assigning, structures provide a simple way to ensure that this is done. That is, if you want assignments to default to copies or values rather than references, use a structure. This is one way to prevent accidental modification of the data in the original entity. |
#7
| |||
| |||
|
|
Kevin Spencer wrote: Another consideration is that a class is a reference type while a structure is a value type. So, if you want to create copies of instances instead of references when assigning, structures provide a simple way to ensure that this is done. That is, if you want assignments to default to copies or values rather than references, use a structure. This is one way to prevent accidental modification of the data in the original entity. Just be aware that: 1) This is a shallow copy. If the struct itself contains reference types, only the references are copied. And, 2) It's not hard to implement the same behavior in a class. If a shallow copy is sufficient, then it's trivial to add a Clone() method (implementing IClonable) that calls Object.MemberwiseClone() to do the same. Personally, I wouldn't call the copying behavior of a struct a significant difference between the two, given the above. But if it's a difference that's of interest, one should at least be aware of the subtleties related to that difference. Pete |
#8
| |||
| |||
|
|
struct is if I have a function that needs to return more than 1 value. For |
|
In addition to what the other responders said. The most common place I use struct is if I have a function that needs to return more than 1 value. For example, suppose you had a function that did integer division. You may want to return a struct that contained both the quotiant and remainder. -- Andrew Faust andrew[at]andrewfaust.com http://www.andrewfaust.com "Bhuwan Bhaskar" <kxxx (AT) gmail (DOT) com> wrote in message news:eyO5O1eFIHA.4752 (AT) TK2MSFTNGP04 (DOT) phx.gbl... Hi, When to use class and when structure in our application? Thanks, Bhuwan |
#9
| |||
| |||
|
|
struct is if I have a function that needs to return more than 1 value. For Kindly explain how a function can return more than one value? |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |