Thread: structs in C#

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Come on, man. This is really easy to google.

    Using Structs (C# Programming Guide)

    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. In such a case, there is no constructor call, which makes the allocation more efficient. However, the fields will remain unassigned and the object cannot be used until all of the fields are initialized.
    If you understand what you're doing, you're not learning anything.

  2. #2
    Registered User
    Join Date
    Apr 2012
    Posts
    37
    Quote Originally Posted by itsme86 View Post
    Come on, man. This is really easy to google.

    Using Structs (C# Programming Guide)

    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. In such a case, there is no constructor call, which makes the allocation more efficient. However, the fields will remain unassigned and the object cannot be used until all of the fields are initialized.
    already googled, that is why I ask.
    Let's see what the quote above says:

    When you create a struct object using the new operator, it gets created and the appropriate constructor is called.
    Alright... In my case there are two variables another and other . And only another gets created with a new operator. Why?

    Moreover, the quote implies that there is an appropriate constructor, but in the code I have, there is no constructor for the firstone struct. So, why use new? and why use new only on one struct variable and not on the other?

    Unlike classes, structs can be instantiated without using the new operator.
    Yes, I can see that, because other never gets instantiated with a new, and yet it is used.

    ----------
    so maybe I should rephrase my question

    Can I use single instances of a struct (like another and other) without using new??

    (for arrays I suppose I should use new)

    (I am starting to think that the guy who wrote the code I have just made a mistake...)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 01-08-2013, 07:55 AM
  2. Typedef Structs inside Typdef structs
    By gremory in forum C Programming
    Replies: 21
    Last Post: 12-30-2011, 07:48 PM
  3. [ noob question ] Help with structs within structs
    By Riverfoot in forum C Programming
    Replies: 3
    Last Post: 04-26-2011, 07:24 PM
  4. Passing Structs Into An Array Of Structs.
    By TheTaoOfBill in forum C Programming
    Replies: 3
    Last Post: 10-07-2010, 09:38 AM
  5. passing structs & pointers to structs as arguments
    By Markallen85 in forum C Programming
    Replies: 6
    Last Post: 03-16-2004, 07:14 PM

Tags for this Thread