How to use Arrays effectively

Karthikanbarasan
Posted by Karthikanbarasan under C# category on | Points: 40 | Views : 1837
using System;

namespace Demo
{
internal class Program
{
private static unsafe void Main()
{
Console.Write("Specify size of array? \n> ");
string UIN = Console.ReadLine();
uint size = uint.Parse(UIN);

long* pArray = stackalloc long[(int) size];
for (int i = 0; i < size; i++)
{
pArray[i] = i*i;
}

for (int i = 0; i < size; i++)
{
Console.WriteLine("Element {0} = {1}", i, *(pArray + i));
}

Console.ReadLine();
}
}
}

Comments or Responses

Posted by: T.saravanan on: 1/17/2011 Level:Silver | Status: [Member] [MVP] | Points: 10
Hi Karthik,

Nice.But i can't understand your code.Can you explain this code and also what is the main use of this?

Login to post response