Prashant Jadhav

Prashant Jadhav

  • NA
  • 38
  • 13.7k

error while assigning object of type to element of reference

Aug 1 2014 6:27 AM
hi guys i was trying to create an class which contain array of reference type
and i was trying to assign same type object to the array element but it was showng me some errors i dont know where i am doing wrong that code is as follow please check it out and tell me where i did wrong
 

using System;
namespace EnumExpl
{
    class employee
    {
        public string firstname;
        public string lastname;
    }
    class employees
    {
       
         employee prashant=new employee()
        {
            firstname="prashant",
            lastname="jadhav"
             


        };
         employee prakash=new employee()
        {
            firstname="prakash",
            lastname="jadhav"
             


        };
        public employee[] Empl = new employee[2];
        Empl[0]=prashant;
         
    }
    class Program
    {
        static void Main(string[] args)
        {
        }
    }

}

Error1Array size cannot be specified in a variable declaration (try initializing with a 'new' expression)c:\users\prashant\documents\visual studio 2010\Projects\enumarator\enumarator\Program.cs2714enumarator


Error2Invalid token '=' in class, struct, or interface member declarationc:\users\prashant\documents\visual studio 2010\Projects\enumarator\enumarator\Program.cs2716enumarator


Error3Invalid token ';' in class, struct, or interface member declarationc:\users\prashant\documents\visual studio 2010\Projects\enumarator\enumarator\Program.cs2725enumarator



these are those error messege i was getting



Answers (9)