CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Threaded View

  1. #1
    Join Date
    Jan 2009
    Posts
    5

    general question about static classes

    What I've created seems to work fine, but I'm wondering if it's ok to do it this way... basically I'm using a static method in a static class to set some default properties for a MailMessage.

    In another method I create two (or more) MailMessages using that static method. Since CreateMessage returns a new MailMessage, does that actually create separate instances, or do all MailMessages created this way refer to the same object because it's a static method (I recall from my C# class only one copy of a static class/method exists)? It all seems to work fine, but what I remember from my C# class makes me think this isn't proper.

    Code:
    public static class Email 
    {
    
    private static MailMessage CreateMessage() {
    MailMessage mm = new MailMessage() //set some properties for mm return mm;
    } public static void New(int issueID) {
    //create first email MailMessage mailToTech = CreateMessage(); //set whatever other properties for mailToTech and send mailToTech mailToTech.Dispose(); //create another email MailMessage mailToUser = CreateMessage(); //set whatever properties and send mailToUser mailToUser.Dispose();
    }
    }
    Last edited by chrisma; January 6th, 2009 at 07:25 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

Featured