Nidhin KR

Nidhin KR

  • NA
  • 1
  • 0

Using sizeof() in c# with arrays

Nov 26 2009 4:18 AM
Hi Team,
I am using sizeof() in c#
I need to find the memory size required by the array which is of the type strut.
Please see the snippet.
 


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Globalization;


namespace sizeOfDemo
{



    struct Vertex
    {
        public float r;
        public float g;
        public float b;
        public float x;
        public float y;
        public float z;
       
       
        public Vertex(float r, float g, float b,float x, float y, float z)
        {
            this.r = r; this.g = g; this.b = b;
            this.x = x; this.y = y; this.z = z;
        }
    }



    public class MainClass
    {

        static void Main(string[] args)
        {
            Console.WriteLine("sizeof operations");
            Vertex[] v = new Vertex[]{
                            new Vertex( 1.0f, 1.0f, 1.0f,  -1.0f, 2.5f, -1.0f ),
                            new Vertex( 1.0f, 1.0f, 1.0f,  -1.0f, 2.5f,  1.0f ),
                            new Vertex( 1.0f, 1.0f, 1.0f,   1.0f, 2.5f,  1.0f ),
                            new Vertex( 1.0f, 1.0f, 1.0f,   1.0f, 2.5f, -1.0f )
                         };
           

            unsafe
            {
               
               
                Console.WriteLine("The size of Vertex is {0}\n", sizeof(Vertex));
                Console.WriteLine("The size of Vertex is {0}\n", sizeof(v));///ERROR here.

                Console.Read();

            }
        }
    }
}


I want the size required for the Vertex Array.Please help me.


Answers (1)