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 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
  • 1 View
  • 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

Related Questions

PHP has a is_readable function which checks to see if the file is readable
My routes.php has the following line of code: Router::connect('/', array('controller' => 'users', 'action' =>
PHP has a lot of trouble with multibyte strings (non-ASCII characters). The entire language
I've been doing some web development work in PHP recently which has led me
PHP has a function range('a','z') which prints the English alphabet a, b, c, d,
I have this page, let's call it index.php index.php has a list of users
This has been bugging me for awhile now. In a deployed PHP web application
Some years ago I created a small website in PHP that now has grown
Each of my pages has http headers in which the language code (two chars)
I'm writing a construct in PHP where a parser determins which function to call

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.