object-reference

.NET XmlSerializer and multiple references to the same object

我与影子孤独终老i 提交于 2020-01-29 06:53:39
问题 My repository has List<Student> , List<Course> and List<Enrolment> where an Enrolment has Enrolment.Student and Enrolment.Course which are references one of the students or courses in the two previous lists. When I use XmlSerializer on my repository it outputs redundant data as it serializes all properties of each student in List<Student> then again for every reference to those same students in List<Enrolment> . I'm looking for an elegant way to solve this. After deserialization I can fix the

.NET XmlSerializer and multiple references to the same object

ε祈祈猫儿з 提交于 2020-01-29 06:50:09
问题 My repository has List<Student> , List<Course> and List<Enrolment> where an Enrolment has Enrolment.Student and Enrolment.Course which are references one of the students or courses in the two previous lists. When I use XmlSerializer on my repository it outputs redundant data as it serializes all properties of each student in List<Student> then again for every reference to those same students in List<Enrolment> . I'm looking for an elegant way to solve this. After deserialization I can fix the

C++ object referencing in classes

耗尽温柔 提交于 2020-01-02 17:13:09
问题 I am wondering how to store a reference of an object inside of another object, and also set that reference as a private property. Example (pseudo-code): class foo { public: int size; foo( int ); }; foo::foo( int s ) : size( s ) {} class bar { public: bar( foo& ); private: foo fooreference; }; bar::bar( foo & reference ) { fooreference = reference; } foo firstclass( 1 ); bar secondclass( firstclass ); As you may be able to see, I just want to be able to store the reference of foo inside this

How Java String pool works when String concatenation?

旧城冷巷雨未停 提交于 2019-12-30 05:24:07
问题 Beware: I'm not trying to compare if the characters are equals. Because I know how to use the String.equals() method. This question is about String reference I was studying for the OCA exam when I started to learn about the class String and it properties as immutability, etc. According to what I read or may understand about String pool is that when a string is created Java stores this object on what they call String pool and if a new string is created with the same value it is going to make

C# Error 'Object Reference Not Set To An Instance Of An Object'

こ雲淡風輕ζ 提交于 2019-12-24 22:18:07
问题 I've read other questions about this but don't see where or why my code is throwing this error. The code I have is below, if anyone can see where i'm going wrong. private void btnSignIn_Click(object sender, EventArgs e) { sqlConnectionNW.ConnectionString = "Data Source=" + server + ";Initial Catalog=Northwind;Integrated Security=True"; try { sqlConnectionNW.Open(); String enteredDate = cmbDay.SelectedItem.ToString() + "/" + cmbMonth.SelectedItem.ToString() + "/" + cmbYear.SelectedItem

How to determine whether object reference is null?

怎甘沉沦 提交于 2019-12-22 01:59:00
问题 What is the best way to determine whether an object reference variable is null ? Is it the following? MyObject myObjVar = null; if (myObjVar == null) { // do stuff } 回答1: Yes, you are right, the following snippet is the way to go if you want to execute arbitrary code: MyObject myObjVar; if (myObjVar == null) { // do stuff } BTW: Your code wouldn't compile the way it is now, because myObjVar is accessed before it is being initialized. 回答2: The way you are doing is the best way if (myObjVar ==

Temporary lifetime extension

≡放荡痞女 提交于 2019-12-21 03:55:06
问题 The 12.2.5 section of standard says: A temporary bound to a reference parameter in a function call (5.2.2) persists until the completion of the full expression containing the call. A temporary bound to the returned value in a function return statement (6.6.3) persists until the function exits. In all these cases, the temporaries created during the evaluation of the expression initializing the reference, except the temporary to which the reference is bound, are destroyed at the end of the full

Java - Preferred design for using a mutable object reference in another thread?

ⅰ亾dé卋堺 提交于 2019-12-14 03:53:37
问题 public class ObjectA { private void foo() { MutableObject mo = new MutableObject(); Runnable objectB = new ObjectB(mo); new Thread(objectB).start(); } } public class ObjectB implements Runnable { private MutableObject mo; public ObjectB(MutableObject mo) { this.mo = mo; } public void run() { //read some field from mo } } As you can see from the code sample above, I pass a mutable object to a class that implements Runnable and will use the mutable object in another thread. This is dangerous

c# - Code that HAS NOT RUN YET is causing an exception? How is this even possible?

﹥>﹥吖頭↗ 提交于 2019-12-13 09:48:20
问题 So I am completely stumped on this one. I am getting an error Object reference not set to an instance of an object. and I am not sure why. I have a class FILE public class FILE { private string _fileName; public string fileName { get { if (!Settings.Values.CaseSensitive) return this._fileName.ToUpper(); else return this._fileName; } set { if (!Settings.Values.CaseSensitive) this._fileName = value.ToUpper(); else this._fileName = value; } } public string folderName { get; set; } public byte[]

Why is this object reference supposedly not set to an instance of an object that has obviously been identified by the compiler?

岁酱吖の 提交于 2019-12-13 09:39:15
问题 Some people -- perhaps gullibly -- believe that there are multiple ways of being a catskinner. When my attempt to search all the Controls on a Page for Checkboxes continued to fail ignominiously (for proof of that, see this), I thought maybe I could just look at the ID of the Control, rather than care what type of control it was at heart. So, I commented out this line: If TypeOf cntrl Is System.Web.UI.WebControls.CheckBox Then ...and tried this instead: If cntrl.ID.ToString().Contains("ckbx")