dont understand this error
im writing a c# console app and have this code:
VB Code:
using System;
namespace Anonymous_Mail_CS
{
/// <summary>
/// Send eMail Anonymousely
/// using any smtp server.
/// </summary>
class Anonymous_Mail_CS
{
System.Web.Mail.MailMessage myMessage = new System.Web.Mail.MailMessage();
static void Main()
{
Console.Write("Specify SMTP Server: ");
System.Web.Mail.SmtpMail.SmtpServer = Console.ReadLine();
Console.Write("Specify 'To': ");
myMessage.To = Console.ReadLine();
Console.Write("Specify 'From': ");
myMessage.From = Console.ReadLine();
Console.Write("Specify 'Subject': ");
myMessage.Subject = Console.ReadLine();
Console.WriteLine("Write your message:");
myMessage.Body = Console.ReadLine();
}
}//end class Anonymous_Mail_CS
}//end namespace Anonymous_Mail_CS
here is the series of errors when trying to build the project:
c:\Visual Studio Projects\Anonymous Mail CS\Class1.cs(21): 'Anonymous_Mail_CS.Anonymous_Mail_CS.myMessage' denotes a 'field' where a 'class' was expected
c:\Visual Studio Projects\Anonymous Mail CS\Class1.cs(24): 'Anonymous_Mail_CS.Anonymous_Mail_CS.myMessage' denotes a 'field' where a 'class' was expected
c:\Visual Studio Projects\Anonymous Mail CS\Class1.cs(27): 'Anonymous_Mail_CS.Anonymous_Mail_CS.myMessage' denotes a 'field' where a 'class' was expected
c:\Visual Studio Projects\Anonymous Mail CS\Class1.cs(30): 'Anonymous_Mail_CS.Anonymous_Mail_CS.myMessage' denotes a 'field' where a 'class' was expected
can i NOT declare a class level variable of MailMessage type?
also, Intellisense doesn't recognize the variable when it's declared where it currently is.
what am i overlooking here?
another thing i'd like to find out is why i have to use a static member of smtpMail (smtpserver) when in visual basic.net, i can use an instance of the smtpMail class? can someone tell me what the difference is between the languages here? :confused:
Re: dont understand this error
Quote:
Originally Posted by Andy
im writing a c# console app and have this code:
VB Code:
using System;
namespace Anonymous_Mail_CS
{
/// <summary>
/// Send eMail Anonymousely
/// using any smtp server.
/// </summary>
class Anonymous_Mail_CS
{
System.Web.Mail.MailMessage myMessage = new System.Web.Mail.MailMessage();
static void Main()
{
Console.Write("Specify SMTP Server: ");
System.Web.Mail.SmtpMail.SmtpServer = Console.ReadLine();
Console.Write("Specify 'To': ");
myMessage.To = Console.ReadLine();
Console.Write("Specify 'From': ");
myMessage.From = Console.ReadLine();
Console.Write("Specify 'Subject': ");
myMessage.Subject = Console.ReadLine();
Console.WriteLine("Write your message:");
myMessage.Body = Console.ReadLine();
}
}//end class Anonymous_Mail_CS
}//end namespace Anonymous_Mail_CS
here is the series of errors when trying to build the project:
c:\Visual Studio Projects\Anonymous Mail CS\Class1.cs(21): 'Anonymous_Mail_CS.Anonymous_Mail_CS.myMessage' denotes a 'field' where a 'class' was expected
c:\Visual Studio Projects\Anonymous Mail CS\Class1.cs(24): 'Anonymous_Mail_CS.Anonymous_Mail_CS.myMessage' denotes a 'field' where a 'class' was expected
c:\Visual Studio Projects\Anonymous Mail CS\Class1.cs(27): 'Anonymous_Mail_CS.Anonymous_Mail_CS.myMessage' denotes a 'field' where a 'class' was expected
c:\Visual Studio Projects\Anonymous Mail CS\Class1.cs(30): 'Anonymous_Mail_CS.Anonymous_Mail_CS.myMessage' denotes a 'field' where a 'class' was expected
can i NOT declare a class level variable of MailMessage type?
also, Intellisense doesn't recognize the variable when it's declared where it currently is.
what am i overlooking here?
another thing i'd like to find out is why i have to use a static member of smtpMail (smtpserver) when in visual basic.net, i can use an instance of the smtpMail class? can someone tell me what the difference is between the languages here? :confused:
hmm that's all the code? the errors seem to be from lines 21, 24, 27, 30... anything on those lines?
Re: dont understand this error
do you need using System.Web.Mail; after using System;
Re: dont understand this error
That sure worked! Thanks. If you use a class level variable anywhere in a console app, you need to mark it as STATIC?
Re: dont understand this error
Quote:
Originally Posted by Andy
That sure worked! Thanks. If you use a class level variable anywhere in a console app, you need to mark it as STATIC?
Nope, you're actually using the console application start up incorrectly. You should be using something along the lines of:
Code:
public class ConsoleApp
{
/// <summary>Fires when the console application is started</sumary>
public static void main(string[] args)
{
ConsoleApp myConsole = new ConsoleApp();
myConsole.Foo();
}
private int classLevelVariable = 0;
/// <summary>Default constructor</summary>
public ConsoleApp()
{
}
/// <summary>The actual console process</summary>
public void Foo()
{
Console.WriteLine("Value = " + classLevelVariable.ToString());
}
}