-> Length

#include "stdafx.h"

using namespace System;

int main(array<System::String ^> ^args)
{
array<double>^ samples = gcnew array<double>(50);

// Generate random element values
Random^ generator = gcnew Random;
for(int i = 0; i < samples->Length; i++)
samples[i] = 100.0*generator->NextDouble();

//output the samples
Console::WriteLine(L"The aray contains the following values:");
for(int i = 0; i < samples->Length; i++)What does -> Length do here in this for loop?
{
Console::Write(L"{0,10:F2}", samples[i]);
if((i+1)%5 == 0) //For each time the loop goes divisible by 5, make a new line
Console::WriteLine();
}
//Find max value
double max(0);
for each(double sample in samples)
if(max < sample)
max = sample;

Console::WriteLine(L"The maximum value in the array is {0:F2}", max);

Console::ReadLine();

return 0;
closed account (zb0S216C)
This is C++/CLI - Microsoft's sorry excuse for garbage collection. In C++, though, the arrow operator (I forgot its actual name) is used with pointers, which effectively dereferences the pointer on the left-hand side, and reads/writes/invokes the member on the right-hand side after dereferencing.

I don't know if this applies to C++/CLI.

Wazzak
Last edited on
Yeah, I'm learning them concurrently in the book that I'm reading. So some of the stuff that the guy covers in CLI isn't quite as clear as it is when he covers it in native C++.
closed account (zb0S216C)
I'd suggest pushing C++/CLI to one side whilst learning C++. Try obtaining another book that focuses solely on C++, and omits non-standard extensions - C++ Primer comes to mind.

Wazzak
Last edited on
The guy rather pushes it to the back burner to be honest. I could just skip them I suppose.
Topic archived. No new replies allowed.