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

  • Home
  • SEARCH
  • 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 1041245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:19:29+00:00 2026-05-16T15:19:29+00:00

PHP has a language construct list() which provides multiple variables assignment in one statement.

  • 0

PHP has a language construct list() which provides multiple variables assignment in one statement.

$a = 0;
$b = 0;
list($a, $b) = array(2, 3);
// Now $a is equal to 2 and $b is equal to 3.

Is there a similar thing in C#?

If not, is there any workaround which may help to avoid code like the following, without having to deal with reflection?

public class Vehicle
{
    private string modelName;
    private int maximumSpeed;
    private int weight;
    private bool isDiesel;
    // ... Dozens of other fields.

    public Vehicle()
    {
    }

    public Vehicle(
        string modelName,
        int maximumSpeed,
        int weight,
        bool isDiesel
        // ... Dozens of other arguments, one argument per field.
        )
    {
        // Follows the part of the code I want to make shorter.
        this.modelName = modelName;
        this.maximumSpeed = maximumSpeed;
        this.weight= weight;
        this.isDiesel= isDiesel;
        /// etc.
    }
}
  • 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-05-16T15:19:29+00:00Added an answer on May 16, 2026 at 3:19 pm

    No, I’m afraid there isn’t any good way to do that, and code like your example gets written often. It sucks. My condolences.

    If you’re willing to sacrifice encapsulation for concision, you can use object initializer syntax instead of a constructor for this case:

    public class Vehicle
    {
        public string modelName;
        public int maximumSpeed;
        public int weight;
        public bool isDiesel;
        // ... Dozens of other fields.
    }
    
    var v = new Vehicle {
        modelName = "foo",
        maximumSpeed = 5,
        // ...
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 537k
  • Answers 537k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I suggest reading the documentation before posting questions. With no… May 17, 2026 at 1:47 am
  • Editorial Team
    Editorial Team added an answer Just encapsulate your application in another class, which you create… May 17, 2026 at 1:47 am
  • Editorial Team
    Editorial Team added an answer The result of the compilation is stored in memory as… May 17, 2026 at 1:47 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm writing a construct in PHP where a parser determins which function to call
PHP has a lot of trouble with multibyte strings (non-ASCII characters). The entire language
I'm trying to solve a problem (in php, but programming language doesn't matter). I'm
I am working on a simplistic website using PHP, a language I haven't touched
My client has a website which is currently semi-static html pages: it contains dynamic
I am asking for advise on which programming language is most acceptable for the
I'm setting up a bunch of different language mediawiki's on one codebase. So far
I'm wishing for a simple index more or less with my PHP note taking
I have a process that has to be ran against certain things and it
I am parsing a HTML document with XPATH and I want to keep all

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.