Attention: We are retiring the ASP.NET Community Blogs. Learn more >

SizeOf

using System;
using System.Reflection ;
using System.Runtime ;

namespace ConsoleTests
{
 
/// <summary>
 /// Summary description for TestSizeOf.
 /// </summary>
 public class TestSizeOf
 {
       
static void Main(string[] args)
        {
            Student[] students =
new Student[3] ;
           
string[] names = new string[] {"darren", "paul", "harry"} ;
           
int[] ages = new int[] {18,21,32} ;
           
string[] descriptions = new string[] {
                               
"A",
                               
"This is a medium description",
                               
"This is a slightly longer description"
                            } ;
           
           
for(int i = 0; i <= names.GetUpperBound(0); i++)
            {
                students[i] =
new Student(names[i],ages[i],descriptions[i]) ;
               
int studentSize = students[i].GetSize() ;
                Console.WriteLine(
"The size of {0} is {1}{2}", names[i], studentSize, Environment.NewLine ) ;
            }
           

            Console.Read() ;
  }
 }

   
public class Student
    {
       
string name ;
       
int age ;
       
string description ;

       
public Student(string name, int age, string description)
        {
           
this.name = name ;
           
this.age = age ;
           
this.description = description ;
        }

       
public int GetSize()
        {
           
return 24 + (4 + (name.Length * 8) + (description.Length * 8)) ;
        }
    }
}

No Comments