0

What is a structure?

help

7th Feb 2017, 10:49 PM
Irah Singson
Irah Singson - avatar
2 ответов
+ 6
A structure is like a box, you place functions, varibles ,etc inside. When you need to use the box, the system will 'duplicate' that box for you to use it. Convinent if you are going to a certain set of same task for mutliple times in your code.
7th Feb 2017, 11:24 PM
Wen Qin
Wen Qin - avatar
+ 1
structs are similar to classes in terms of their ability to contain fields, methods and constructors. However structs are NOT classes, they're value types whereas classes are reference types. You'd like to use structs to encapsulate a small set of data. Actually ints,double, float, long etc are structures. Below shows an example of struct. struct Time { private int hour; private int minutes; private int seconds; public Time(int hr, int mins, int Seconds){ hour = hr; minutes = mins; seconds = Seconds; } public override string ToString(){ return hour +":"+ minutes +":"seconds; } } you can use it like this: Time now = new Time(13,50,34); Console.Write(now); // keep in mind even though i am using "new " keyword here, it is NOT an object , it's still a value type stored in stack memory.
8th Feb 2017, 2:02 AM
Ousmane Diaw