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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:33:15+00:00 2026-05-25T12:33:15+00:00

I am new to c# and use it with unity3D. When I use the

  • 0

I am new to c# and use it with unity3D. When I use the new keyword to initialize an object it seems to have null in it even though the object is created and the constructor executes:

public class Wire
{
  public Wire()
  { 
    System.Console.WriteLine("constructor executed");
    System.Console.WriteLine(this);
  }
}

Wire wire1 =new Wire();
System.Console.WriteLine(wire1);

The output is:

constructor executed
null
null

I need to store the reference in a list but now I can’t. How can I solve this problem?


ok the actual code is

public class SharedResources
{    
    public static Dictionary< GameObject , Wire> dict = 
       new Dictionary<GameObject, Wire>();
    //...
}

public class Wire
{
    public GameObject x = y.y; 
    //y.y is another gameobject so its a normal copy constructer

    public Wire()
    { 
        print("constructor executed"); 
        // print is provided from unity package
        SharedResources.dict.Add( x,this);
    }
}

and in the main i have

Wire wire1 = new Wire();
if ( SharedResources.dict.ContainsKey( wire1.x) )
{
    print("ok"); // it does print that!!
    if ( SharedResources.dict[wire1.x] !=null )
        print("its not null");
    else
        print("its null");
}

output:

constructor executed
ok
its null

  • 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-25T12:33:16+00:00Added an answer on May 25, 2026 at 12:33 pm

    That is not possible.

    The this keyword can never be a null reference, a constructor can never return a null reference, and calling Console.WriteLine with a null reference doesn’t display “null”, it displays an empty line, i.e the same as Console.WriteLine(String.Empty).

    You can get that behaviour if you override the ToString method to return the string "null":

    public class Wire {
    
      public Wire() {
        System.Console.WriteLine("constructor executed");
        System.Console.WriteLine(this);
      }
    
      public override string ToString() {
        return "null";
      }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I m new to use ankhSVN and having issues. I have created some new
I have the following snippet of code that's generating the Use new keyword if
Why is it necessary to use the new keyword when a method shall be
There are two ways of creating an object in javascript: use new on a
I'm trying to use new-style properties declaration: class C(object): def __init__(self): self._x = 0
i m new use of unity3d softwere. i am facing a problem with First
I am trying to create a reusable javascript object (I want to use new).
We have successfully migrated all of our PHP and Ruby apps to use New
I came across a new use of the keyword typedef in C++. What does
I am new to use UIImagePickerController in iPhone applications. I have added two UIButtons

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.