As I’m writing applications using C++ .NET framework I want to ask a question.
When I am writing code exactly for “for loop” I always use this style of coding:
for( int i=0; i<somevalue; ++i ) {
// Some code goes here.
}
but as I am using C++ .NET I can write
for( System::Int32 i=0; i<somevalue; ++i ) {
// Some code goes here.
}
I think there are no difference Am I right ? If no can you explain whats the difference between this two ways and. witch one is more effective ?
The only difference is probably being explicit about the range of values supported by
intandSystem::Int32.System::Int32makes the 32-bitness more explicit to those reading the code. One should useintwhere there is just need of ‘an integer’, and useSystem::Int32where the size is important (cryptographic code, structures) so readers will be clear of it while maintaining the same.Using
intorSystem::Int32the resulting code will be identical: the difference is purely one of explicit readability or code appearance.