Results 1 to 7 of 7

Thread: dont understand this error

Threaded View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489

    Resolved dont understand this error

    im writing a c# console app and have this code:
    VB Code:
    1. using System;
    2.  
    3. namespace Anonymous_Mail_CS
    4. {
    5.     /// <summary>
    6.     /// Send eMail Anonymousely
    7.     /// using any smtp server.
    8.     /// </summary>
    9.     class Anonymous_Mail_CS
    10.     {
    11.  
    12.             System.Web.Mail.MailMessage myMessage = new System.Web.Mail.MailMessage();
    13.  
    14.         static void Main()
    15.         {
    16.  
    17.             Console.Write("Specify SMTP Server: ");
    18.             System.Web.Mail.SmtpMail.SmtpServer = Console.ReadLine();
    19.  
    20.             Console.Write("Specify 'To': ");
    21.             myMessage.To = Console.ReadLine();
    22.  
    23.             Console.Write("Specify 'From': ");
    24.             myMessage.From = Console.ReadLine();
    25.  
    26.             Console.Write("Specify 'Subject': ");
    27.             myMessage.Subject = Console.ReadLine();
    28.  
    29.             Console.WriteLine("Write your message:");
    30.             myMessage.Body =  Console.ReadLine();
    31.            
    32.            
    33.         }
    34.    
    35.     }//end class Anonymous_Mail_CS
    36. }//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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width