Chapter 26. C structures


Chapter 26. C# structures

Structs (structures) in the C language were used very commonly long before OO programming became popular. [1] They are used to group together multiple primitive data types to create a new data type (or data structure). Today, OO classes have taken over much of the functionality of structs, but they are still relevant in C# because careful use of structs can improve the performance of a program significantly. [2]

[1] Structs in C# are slightly different from structs in C++ (and significantly different from the original structs in C). So even if you are familiar with C/C++, it is not recommended to skip this chapter.

[2] I have to note too, that poor use of structs can also decrease performance. For this reason, I think section 26.3 is an important read.

If you are not familiar with structs at all, just think of them as being very similar to classes. Simplistically speaking, structs can be viewed as classes with certain limitations. I shall start with a brief example involving structs so that you can see the similarity between structs and classes. The quickest way to learn about structs if you already know about classes is to highlight their differences “ I will do that after the example. This chapter concludes with an important discussion on the circumstances whereby you would prefer to use a struct rather than a class.



From Java to C#. A Developers Guide
From Java to C#: A Developers Guide
ISBN: 0321136225
EAN: 2147483647
Year: 2003
Pages: 221
Authors: Heng Ngee Mok

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net