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?
Use
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()ornew 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 justnew []{1, 2, 3}