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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:11:24+00:00 2026-06-18T15:11:24+00:00

I have a struct type called Node like below: struct Node { int data;

  • 0

I have a struct type called Node like below:

struct Node
{
    int data;
    Node next; 
}

I get compile time error when I compile above code but If I make it a class everything is fine.

class Node
    {
        int data;
        Node next; 
    }

What is the difference between two ( I know one is struct ( value type ) and one is class(ref type ) ) ?

  • 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-06-18T15:11:25+00:00Added an answer on June 18, 2026 at 3:11 pm

    Have you ever programmed in C-class language? You know, classes/structures and pointers and such?

    If you had so, then remember: in C# “classes” are passed “as pointers”, while “structs” are passed in they raw binary form, they are copied around just like anything non-pointerish non-referencish in C/C++. All other restrictions for nesting are preserved, just named differently.

    In C# you can have a ‘class X’ containing a field of type ‘class X’ because “classes” are never placed anywhere directly. Such field is actually a 4/8 byte pointer/reference. The size of ‘class X’ is easily determinable. In contrast, in C# you cannot have a ‘struct X’ that contains a field of type ‘struct X’. Such field would be embeded in the outer struct directly, not by pointer/reference. What would be the size of the ‘struct X’ if it contained another ‘struct X’ which surely by its definition would contain another ‘struct X’ that would contain …. where would be the end? How would you mark the end? How the compiler/runtime would know how much space to allocate when you write “new X()” ? Just as in C/C++ you cannot create recursively nested types directly (you can do that only by pointers/references), here in C# you cannot create recursive structs.

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

Sidebar

Related Questions

I have a struct called CoolStruct: struct CoolStruct { int id; uint32 type; uint32
I have a struct that has a field called type How do i access
I have queue from struct type struct test { int numbers; }; queue<test> q;
I have a C struct like this: typedef struct { my_domain_type_t type; my_domain_union_t u;
Say I have a type edge: struct edge { long long weight; int dest;
I have this type which is basically a struct { int x,y,z; } that
I have in my program a struct type called Square which is used to
I have a pointer to a C type wrapped by a Go struct, like
I have a struct of type Duplicate I have a variable of type int
I have a structured a data type called bookStruct and books is the name

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.