LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Data Type in Programming (https://www.linuxquestions.org/questions/linux-newbie-8/data-type-in-programming-814030/)

elizas 06-14-2010 06:13 AM

Data Type in Programming
 
I declared a variable as int data type which was a placeholder for a result status (meaning, based on the result status that variable varies from 0/1/2/3. It can contain only these four values).

“int” data type is 4 byte integer in C#. But I can declare this variable as “sbyte” which represents a 1 byte integer. Since that variable contains only 1 or 2 or 3 or 4, declaring the variable as “int” is wastage of memory space.

Before declaring any variable we need to just think of the memory space needed for that variable, our requirement, any other good alternative for this variable.

<<mod edit: delete advertising link>>

dracuss 06-14-2010 06:19 AM

elizas, I'm not a very experimented programmer, but I would suggest using the enum type. In C it's not very different from int, but as much as I know it will ease your life a bit.

pixellany 06-14-2010 06:19 AM

Elizas;
If you want to advertise here, please see the links at the bottom of the page.

elizas 06-14-2010 06:31 AM

Data Type in Programming
 
I declared a variable as “int” data type for a PatientId. It worked fine in local, but when that code went to LIVE, the application gave exception because in LIVE PatientId is too long to accommodate in int data type.

So before declaring any variable we need to consider all the situations, application scope, environment .Even one code may be working fine today, after 1/ 10/20 days/months/years it will fail due to just due to data type declaration mistake.

Think more; write less is the policy for better programming.

My Experience No 2:

I declared a variable as int data type which was a placeholder for a result status (meaning, based on the result status that variable varies from 0/1/2/3. It can contain only these four values).

“int” data type is 4 byte integer in C#. But I can declare this variable as “sbyte” which represents a 1 byte integer. Since that variable contains only 1 or 2 or 3 or 4, declaring the variable as “int” is wastage of memory space.

Before declaring any variable we need to just think of the memory space needed for that variable, our requirement, any other good alternative for this variable.

<<mod edit: deleted advertising link>>

pixellany 06-14-2010 06:36 AM

Second warning: Do not include the advertising link in any future posts

MTK358 06-14-2010 07:32 AM

Why didn't the OP mention C# in the title?

And why isn't this in the Programming forum?

pixellany 06-14-2010 09:13 PM

1. probably because the posts were motivated by advertising (now removed)

2. because it may just get closed or deleted


All times are GMT -5. The time now is 02:30 AM.