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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:57:20+00:00 2026-06-10T18:57:20+00:00

How do I require that all of the objects in a parameter array be

  • 0

How do I require that all of the objects in a parameter array be passed as out? In my following code, I know that it’s failing because my original parameters never get assigned and are thus null. Even though I would think they’d be passed as reference without having to explicitly say so, they don’t seem to be. As a result, I’ve had to try and pass all of it as an out parameter.

Here’s the parts of my code that I think matter.

ChatController(some elements removed)

class ChatController : ControllerBase
{
    #region Views

    ChatAreaView viewChatArea;
    UserListView viewUserArea;
    MessageView viewMessageArea;
    LoginPromptView viewLoginPrompt;

    #endregion

    #region ViewModels

    ChatAreaViewModel viewModelChatArea;
    UserAreaViewModel viewModelUserArea;
    MessageAreaViewModel viewModelMessageArea;
    LoginPromptViewModel viewModelLoginPrompt;

    #endregion
    public override void CreateViewsAndViewModels()
    {
        //InitializeViewAndViewModel(out viewChatArea, out viewModelChatArea);
        //InitializeViewAndViewModel(out viewMessageArea, out viewModelMessageArea);
        //InitializeViewAndViewModel(out viewUserArea, out viewModelUserArea);
        //InitializeViewAndViewModel(out viewLoginPrompt, out viewModelLoginPrompt);

        InitializeViewsAndViewModels(new FrameworkElement[] { viewChatArea, viewUserArea, viewMessageArea, viewLoginPrompt },
                                     new object[] { viewModelChatArea, viewModelUserArea, viewModelMessageArea, viewModelLoginPrompt });
    }
}

ControllerBase(some elements removed)

public abstract class ControllerBase : PrismBase
{
    public void InitializeViewAndViewModel<TView, TViewModel>(out TView view, out TViewModel viewModel)
        where TView : FrameworkElement, new()
        where TViewModel : new()
    {
        view = new TView();
        viewModel = new TViewModel();

        view.DataContext = viewModel;
    }

    public void InitializeViewsAndViewModels(FrameworkElement[] views, object[] viewModels)
    {
        if (views.Length != viewModels.Length)
            throw new ArgumentOutOfRangeException("views and viewModels must have the same number of elements.");

        for (int i = 0; i < views.Length -1 ; i++)
            InitializeViewAndViewModel(out views[i], out viewModels[i]);
    }
}

The problem area is here

public void InitializeViewsAndViewModels(FrameworkElement[] views, object[] viewModels)
{
}

All these objects here that I pass in to the method remain null when the method returns.

InitializeViewsAndViewModels(new FrameworkElement[] { viewChatArea, viewUserArea, viewMessageArea, viewLoginPrompt },
                             new object[] { viewModelChatArea, viewModelUserArea, viewModelMessageArea, viewModelLoginPrompt });

I want to require passing all of the views and viewModels array objects as out, but I can only seem to require the entire array itself be passed as out.

What can I do here?

EDIT: The entire problem seems to stem from the Plural form of the method, as I described above. If I got rid of that and I simply did this…

public override void CreateViewsAndViewModels()
{
    InitializeViewAndViewModel(out viewChatArea, out viewModelChatArea);
    InitializeViewAndViewModel(out viewMessageArea, out viewModelMessageArea);
    InitializeViewAndViewModel(out viewUserArea, out viewModelUserArea);
    InitializeViewAndViewModel(out viewLoginPrompt, out viewModelLoginPrompt);

    //InitializeViewsAndViewModels(new FrameworkElement[] { viewChatArea, viewUserArea, viewMessageArea, viewLoginPrompt },
    //                             new object[] { viewModelChatArea, viewModelUserArea, viewModelMessageArea, viewModelLoginPrompt });
}

everything works just swimmingly.

  • 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-10T18:57:21+00:00Added an answer on June 10, 2026 at 6:57 pm

    You can’t have arrays of out values in C#.

    Now what you are trying to do is very strange and even if arrays of out would be supported you will still endup with trobles – you are loosing types of variable in you arrays, so there is no reasoanble way to new them up correctly.

    Your current generic methods have multiple implementations in derived classes – one per pair of types (i.e. your ChatController have what you can view as 4 distinct implementation of InitializeViewAndViewModel each for specific pair of views). Your newly proposed code would have to find that missing type information somehow…

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

Sidebar

Related Questions

I have a WCF service with operations that all require MyServiceRequest parameter (or derived
I have an intermediary class extending System.Web.UI.Page for all of my pages that require
There are many Cocoa methods that require an NSError object as a parameter to
I am trying to figure out where to store collections of objects that are
PHP, as we all know is very loosely typed. The language does not require
I recently had to run a job that required all the mappers to finish
I'm writing a driver that requires me to clear all the memory allocated to
Is there a way to require that a class have a particular abstract member?
In my live site I have php include() and require() that have full path
In Visual Studio, you can require that an assembly reference match a specific version

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.