|
-
Mar 1st, 2005, 09:46 PM
#1
Thread Starter
Frenzied Member
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?
Last edited by Andy; Apr 5th, 2005 at 08:36 PM.
-
Mar 2nd, 2005, 01:07 AM
#2
Re: dont understand this error
 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? 
hmm that's all the code? the errors seem to be from lines 21, 24, 27, 30... anything on those lines?
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Mar 2nd, 2005, 06:28 AM
#3
Re: dont understand this error
do you need using System.Web.Mail; after using System;
-
Mar 2nd, 2005, 08:48 AM
#4
Sleep mode
Mark the vari "myMessage" as 'static' .
-
Mar 6th, 2005, 12:37 PM
#5
Thread Starter
Frenzied Member
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?
-
Mar 6th, 2005, 01:57 PM
#6
Re: dont understand this error
 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());
}
}
-
Mar 7th, 2005, 04:53 AM
#7
Sleep mode
 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?
It depends on the logic and the functionality you're making . It requires more OOP read . To sum up, variables accessibility and visiblity (info hiding) :
if you want to reference a non-static variable in static method , then you have to have object reference of that class first .
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|