Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8052825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:39:30+00:00 2026-06-05T07:39:30+00:00

Example: public class EmailBusinessLogic { #region Fields and Constructors SmtpClient smtp; Parameter prm; public

  • 0

Example:

public class EmailBusinessLogic
{
    #region Fields and Constructors
    SmtpClient smtp;
    Parameter prm;

    public EmailBusinessLogic()
    {
        prm = CostHelper.GetParameter();
        smtp = new SmtpClient(prm.EmailHost, prm.EmailPort);
        smtp.UseDefaultCredentials = prm.EmailUseDefaultCredentials;
        smtp.DeliveryMethod = GetDeliveryMethod(prm.EmailDeliveryMethod); //CALL TO METHOD DOWN BELOW, IS THIS A GOOD PRACTICE?
        smtp.EnableSsl = prm.EmailEnableSSL;
        smtp.Credentials = new NetworkCredential(prm.AppUserName, prm.AppPass, prm.AppNetworkDomain);

    }
    #endregion

    #region Instance Methods
    public SmtpDeliveryMethod GetDeliveryMethod(string name)
    {
        switch (name)
        {
            case "Network": return SmtpDeliveryMethod.Network;
            case "IISDirectory": return SmtpDeliveryMethod.PickupDirectoryFromIis;
            case "OtherDirectory": return SmtpDeliveryMethod.SpecifiedPickupDirectory;
            default: throw new NonExistentObjectException();
        }
    } 

I am asking this because its a small paradox, i know the constructor always gets called first when instantiating this class into a new object. And i would not want to make it a static method because that will create a static instance that does not get garbage collected.

If i am wrong please correct me, a clear answer from an experienced fellow programmer is highly welcome. Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T07:39:32+00:00Added an answer on June 5, 2026 at 7:39 am

    Calling a non-static method in the constructor can be ok – but you should avoid it for virtual methods, because if the method is overridden the actual method will be called on a type that hasn’t had the type-level constructor invoked yet – can cause problems.

    Calling a static method would be more reliable. I think your reasons for not wanting a static method are a bit confused, and do not apply. There is absolutely no reason to avoid a static method. A static method is not implemented as an instance method on a “static instance that does not get garbage collected”. There is no instance for a static method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For example: Public Class Class1 Public Sub Some() Dim Image As New Bitmap(C:\image.bmp) End
Example threadpool: public class Example { public static void Main() { ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc)); //task
How do I check generic subtypes passed as parameter? For example: public class A<T>
Example: public class TestClass { public static void main(String[] args) { TestClass t =
Take this class as example: public class Category : PersistentObject<int> { public virtual string
I have this example: public class Inheritance { public static class Animal { public
For example public interface X{ public void foo(X i); } public class Y implements
Let's have a following example: public class X { } public class Y {
I want to create a template class in C#, for example: public class Foo<T>
Say suppose I have the following Java code. public class Example { public static

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.