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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:30:17+00:00 2026-05-29T10:30:17+00:00

In C#, Structs are managed in terms of values, and objects are in reference.

  • 0

In C#, Structs are managed in terms of values, and objects are in reference. From my understanding, when creating an instance of a class, the keyword new causes C# to use the class information to make the instance, as in below:

class MyClass
{
    ...
}
MyClass mc = new MyClass();

For struct, you’re not creating an object but simply set a variable to a value:

struct MyStruct
{
    public string name;
}
MyStruct ms;
//MyStruct ms = new MyStruct();     
ms.name = "donkey";

What I do not understand is if declare variables by MyStruct ms = new MyStruct(), what is the keyword new here is doing to the statement? . If struct cannot be an object, what is the new here instantiating?

  • 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-29T10:30:18+00:00Added an answer on May 29, 2026 at 10:30 am

    From struct (C# Reference) on MSDN:

    When you create a struct object using the new operator, it gets created and the appropriate constructor is called. Unlike classes, structs can be instantiated without using the new operator. If you do not use new, the fields will remain unassigned and the object cannot be used until all of the fields are initialized.

    To my understanding, you won’t actually be able to use a struct properly without using new unless you make sure you initialise all the fields manually. If you use the new operator, then a properly-written constructor has the opportunity to do this for you.

    Hope that clears it up. If you need clarification on this let me know.


    Edit

    There’s quite a long comment thread, so I thought I’d add a bit more here. I think the best way to understand it is to give it a go. Make a console project in Visual Studio called “StructTest” and copy the following code into it.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace struct_test
    {
        class Program
        {
            public struct Point
            {
                public int x, y;
    
                public Point(int x)
                {
                    this.x = x;
                    this.y = 5;
                }
    
                public Point(int x, int y)
                {
                    this.x = x;
                    this.y = y;
                }
    
                // It will break with this constructor. If uncommenting this one
                // comment out the other one with only one integer, otherwise it
                // will fail because you are overloading with duplicate parameter
                // types, rather than what I'm trying to demonstrate.
                /*public Point(int y)
                {
                    this.y = y;
                }*/
            }
    
            static void Main(string[] args)
            {
                // Declare an object:
                Point myPoint;
                //Point myPoint = new Point(10, 20);
                //Point myPoint = new Point(15);
                //Point myPoint = new Point();
    
    
                // Initialize:
                // Try not using any constructor but comment out one of these
                // and see what happens. (It should fail when you compile it)
                myPoint.x = 10;
                myPoint.y = 20;
    
                // Display results:
                Console.WriteLine("My Point:");
                Console.WriteLine("x = {0}, y = {1}", myPoint.x, myPoint.y);
    
                Console.ReadKey(true);
            }
        }
    }
    

    Play around with it. Remove the constructors and see what happens. Try using a constructor that only initialises one variable(I’ve commented one out… it won’t compile). Try with and without the new keyword(I’ve commented out some examples, uncomment them and give them a try).

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

Sidebar

Related Questions

Clojure structs can be arbitrarily extended, adding new fields. Is it possible to extend
When should someone use structs instead of classes or vice versa in C++? I
C# doesn't allow structs to derive from classes, but all ValueTypes derive from Object.
I'm studying .NET structs - some books advise creating structs if they have an
Has anyone managed to do this? I tried making a managed wrapper class for
I'm trying to subclass an unmanaged statusbar window from my managed COM server using
I'm having some trouble with this code: //Creating a new ImageElement Struct ImageElement oElement
So I have managed to find another question discussing how to use the libjpeg
I've managed to port RC4 implementation from PolarSSL to delphi, since I need an
I've managed to create a struct for UserData, but when I switch from using

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.