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 9223447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:05:01+00:00 2026-06-18T04:05:01+00:00

I use this code to load a MDIchild form from within another MDIchild form.

  • 0

I use this code to load a MDIchild form from within another MDIchild form. I’m learning still how to use generics in my method so when I get my method to work finally with the help of the people here I end u with two slightly different codes which in my case do the job the same way. So my question is – is it coincidence that those two variations do the same job or there’s just no difference between the two approaches.

So here is version 1:

protected void LoadAForm<T>(ref T sendTo) where T : Form
{
    MainForm frm = this.MdiParent as MainForm;
    if (frm != null)
    {
        sendTo = SingletonFormProvider.GetInstance<T>(frm, true);
        sendTo.MdiParent = frm;
        sendTo.Dock = DockStyle.Fill;
        sendTo.Show();
    }
}

And here is version 2:

protected void LoadAForm<T>(ref T sendTo) where T : Form
{
    MainForm frm = this.MdiParent as MainForm;
    T temp;
    if (frm != null)
    {
        temp= SingletonFormProvider.GetInstance<T>(frm, true);
        temp.MdiParent = frm;
        temp.Dock = DockStyle.Fill;
        temp.Show();
    }
}

So is there (if any difference) to use the T temp instantiation or it’s just the same thing?

  • 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-18T04:05:02+00:00Added an answer on June 18, 2026 at 4:05 am

    The main difference is that in the 2nd scenario, your newly created and shown form will not be available outside LoadAForm in your sendTo param.
    The first method seems to work correctly, accomplishing what it was intended for by passing a reference parameter to it.

    Another natural way is to return the newly created as a function return value form instead of returning it throug a ref’ed parameter.

    LATER EDIT:
    Frankly said, as Henk Holterman said, you are misusing the ref usage.

    By the way, if you still want to pass a parameter to that method, use out instead of ref!

    Ok, this is what I mean: declare your method like this:

    protected T LoadAForm<T>() where T : Form
    

    and return the form you just instantiated. Simple.

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

Sidebar

Related Questions

I use this code to load the content from a different page into the
I use this code to load a .Net assembly to PowerShell: [System.Reflection.Assembly]::Load(System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
I use this code to select password field from the sql server 2012 db,
I use this code to process a date string coming in from a json
I use this code which is taken from MVC futures and attach the Attribute
I use this code to load a htmlbox-instance to my page (this page also
I'm trying to run this code but I get this error anytime I use
I use this code to load an Excel file into a datatable: public static
I try to load specific location in same page. so I use this code
I use this code below to load CSS files. var i, a; for(i=0; (a

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.