C# Error A New Expression Requires Or After Type
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up c# compiler error CS1526: A new expression requires (), [], or {} after type up vote 4 down vote favorite I am following a tutorial to create a class: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace Session3 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Vehicle my_Car = new Vehicle; } } class Vehicle { uint mileage; byte year; } } I am getting the mentioned error on this line: private void button1_Click(object sender, EventArgs e) { Vehicle my_Car = new Vehicle; } Does anyone know what I am doing wrong? c# constructor compiler-errors share|improve this question edited Jun 25 '15 at 14:50 CodesInChaos 74.8k10136194 asked Oct 11 '10 at 19:17 l--''''''---------'''''''''''' 13.9k169437749 1 try this: Vehicle my_Car = new Vehicle(); –Crag Oct 11 '10 at 19:19 add a comment| 4 Answers 4 active oldest votes up vote 12 down vote accepted Use Vehicle my_Car = new Vehicle(); To call a constructor you need () after the class name, just like for function calls. One of the following is required: () for a constructor call. e.g. new Vehicle() or new Vehicle(...) {} as an initializer, e.g. new Vehicle { year = 2010, mileage = 10000} [] for arrays, e.g. new int[3], new int[]{1, 2, 3} or even just new []{1, 2, 3} share|improve th
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up A new expression requires (), [], or {} after type in mvc controller http://stackoverflow.com/questions/3909244/c-sharp-compiler-error-cs1526-a-new-expression-requires-or-after-typ up vote 0 down vote favorite This is quite strange but I m getting this error A new expression requires (), [], or {} after type on the following line in a controller action method int[] Numbers = { 1, 2, 3, 4, 5}; or I have also tried var Numbers = new int[]{1,2,3,4,5}; Also tried few other ways of getting this line work but it won't. Other than controller http://stackoverflow.com/questions/28952526/a-new-expression-requires-or-after-type-in-mvc-controller action methods this works perfectly fine. Any ideas about this weird behavior? I m using VS 2013 express edition MVC version 5 and .net framework 4.5 Here is complete action method public ActionResult Index() { var LstMainModel=new List
Languages , .NET Framework > Visual C# Question 0 Sign in to vote Dictionary