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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:51:36+00:00 2026-05-15T20:51:36+00:00

I have a class roughly designed as such: class Vector3 { float X; float

  • 0

I have a class roughly designed as such:

class Vector3
{
    float X;
    float Y;
    float Z;

    public Vector3(float x, float y, float z)
    {
        this.X = x;
        this.Y = y;
        this.Z = z;
    }
}

I have other classes implementing it as properties, for example:

class Entity
{
    Vector3 Position { get; set; }
}

Now to set an entity’s position, I use the following:

myEntity.Position = new Vector3(6, 0, 9);

I would like to shorten this up for the user by implementing an array-like initializer for Vector3:

myEntity.Position = { 6, 0, 9 };

However, no class can inherit arrays. Moreover, I know I could somehow manage to get this with minor hacks:

myEntity.Position = new[] { 6, 0, 9 };

But this is not the point here. 🙂

Thanks!

  • 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-15T20:51:37+00:00Added an answer on May 15, 2026 at 8:51 pm

    There is no defined syntax to use array initializer syntax, except for in arrays. As you hint, though, you can add an operator (or two) to your type:

        public static implicit operator Vector3(int[] value)
        {
            if (value == null) return null;
            if (value.Length == 3) return new Vector3(value[0], value[1], value[2]);
            throw new System.ArgumentException("value");
        }
        public static implicit operator Vector3(float[] value)
        {
            if (value == null) return null;
            if (value.Length == 3) return new Vector3(value[0], value[1], value[2]);
            throw new System.ArgumentException("value");
        }
    

    Then you can use:

    obj.Position = new[] {1,2,3};
    

    etc. However, personally I’d just leave it alone, as:

    obj.Position = new Vector3(1,2,3);
    

    which involves less work (no array allocation / initialization, no operator call).

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

Sidebar

Related Questions

I have a class that roughly looks like this: public class ViewModel { public
This is (roughly) what I have: class A { public bool IsInUpdate = false;
I have class with back reference: public class Employee : Entity { private string
So I have a PHP stack that looks roughly like this Class Stack {
Let's say I have objects which look very roughly like this: class object {
I have an entity which is declared roughly like: @Entity @Table(name = myUserTable) public
I have a class that looks roughly like this: template<std::size_t dim> class Foo {
I have a c#-class that looks roughly like this: class ImageContainer { Image image;
I have a tree like structure roughly like this: class Node < ActiveRecord::Base belongs_to
I have class with collection as below public class MyClass:IXmlSerializable { int vesrion; private

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.