cna't compile

  • Thread starter Thread starter js
  • Start date Start date
J

js

got the error when I try to compile(csc AsyncResolve.cs):
AsyncResolve.cs(6,20): error CS1514: { expected
AsyncResolve.cs(6,24): error CS1519: Invalid token ':' in class, struct, or
interface member declaration

What's the problem? Please advice.


AsyncResolve.cs
=========================
using System;
using System.Drawing;
using System.Net;
using System.Text;
using System.Windows.Forms;
class AsyncResolve Form:
{
TextBox address;
ListBox results;
private AsyncCallback OnResolved;
public AsyncResolve()
{
Text = "DNS Address Resolver";
Size = new Size(400,380);
OnResolved = new AsyncCallback(Resolved);
Label label1 = new Label();
label1.Parent = this;
label1.Text = "Enter address to resolve:";
label1.AutoSize = true;
label1.Location = new Point(10, 10);
address = new TextBox();
address.Parent = this;
address.Size = new Size(200, 2 * Font.Height);
address.Location = new Point(10, 35);
results = new ListBox();
results.Parent = this;
results.Location = new Point(10, 65);
results.Size = new Size(350, 20 * Font.Height);
Button checkit = new Button();
checkit.Parent = this;
checkit.Text = "Resolve";
checkit.Location = new Point(235,32);
checkit.Size = new Size(7 * Font.Height, 2 * Font.Height);
checkit.Click += new EventHandler(ButtonResolveOnClick);
}
void ButtonResolveOnClick(object obj, EventArgs ea)
{
results.Items.Clear();
string addr = address.Text;
Object state = new Object();
Dns.BeginResolve(addr, OnResolved, state);
}
private void Resolved(IAsyncResult ar)
{
string buffer;
IPHostEntry iphe = Dns.EndResolve(ar);
buffer = "Host name: " + iphe.HostName;
results.Items.Add(buffer);
foreach(string alias in iphe.Aliases)
{
buffer = "Alias: " + alias;
results.Items.Add(buffer);
}
foreach(IPAddress addrs in iphe.AddressList)
{
buffer = "Address: " + addrs.ToString();
results.Items.Add(buffer);
}
}
public static void Main()
{
Application.Run(new AsyncResolve());
}
}
 
js said:
got the error when I try to compile(csc AsyncResolve.cs):
AsyncResolve.cs(6,20): error CS1514: { expected
AsyncResolve.cs(6,24): error CS1519: Invalid token ':' in class, struct, or
interface member declaration

What's the problem? Please advice.

There are two problems here. One is that you have made
no attempt to reduce your code to something that is both
minimal and reproduces the problem. That is a common
and useful way to discover those sytax errors that we
sometimes become blind to. It is also a courtesy to
those who may try to help you find it.

I reduced your code to this:
using System;
using System.Drawing;
using System.Net;
using System.Text;
using System.Windows.Forms;
class AsyncResolve Form:
{
public static void Main()
{
Application.Run(new AsyncResolve());
}
}

Changing line 6 to this fixes it:
class AsyncResolve : Form
 
You may also want to change this line

class AsyncResolve Form:

->

class AsyncResolve : Form
 
Morten Wennevik said:
You may also want to change this line

class AsyncResolve Form:

->

class AsyncResolve : Form

Um, isn't that exactly what Larry pointed out? :)
 
Back
Top