reference-type

(C#) How to copy classes by value type and not reference type?

做~自己de王妃 提交于 2021-02-10 06:40:28
问题 Take the following code: using System.Collections; using System.Collections.Generic; using UnityEngine; public class MyClass { public int myNumber; } public class Test : MonoBehaviour { MyClass class1 = new MyClass(); MyClass class2 = new MyClass(); void Start() { class1.myNumber = 1; class2 = class1; class2.myNumber = 2; Debug.Log(class1.myNumber); //output: 2 (I'd want it to output 1!!!) } } Now, if I understood correctly, in C# classes are a reference type and not a value type, so this

Specify that an interface can only be implemented by reference types C#

橙三吉。 提交于 2021-02-07 12:31:10
问题 If I declare an interface in C#, is there any way I can explicitly declare that any type implementing that interface is a reference type? The reason I want to do this is so that wherever I use the interface as a type parameter, I don't have to specify that the implementing type also has to be a reference type. Example of what I want to accomplish: public interface IInterface { void A(); int B { get; } } public class UsingType<T> where T : IInterface { public void DoSomething(T input) {

why string, array and dictionary in Swift changed to value type

偶尔善良 提交于 2021-02-05 20:19:35
问题 In Objc string, array and dictionary are all reference types, while in Swift they are all value types. I want to figure out what's the reason behind the scenes, for my understanding, no matter it is a reference type or value type, the objects live in the heap in both Objc and Swift. Was the change for making coding easier? i.e. if it is reference type then the pointer to the object might not be nil, so need to check both pointer and the object not nil for accessing the object. While if it is

Insert Dimensions to complete Expression/ReferenceType

蹲街弑〆低调 提交于 2020-11-27 04:43:17
问题 I'm a newbie to Java. I have provided a short snippet from my code for BFS. public int bfs(Person p, Person q) { private HashMap<Person, boolean> marked; private int count; marked = new marked<Person, boolean>(); count = new int; } According to Eclipse, I have an error on each of the last 4 lines. Syntax Error: insert "Dimensions" to complete expression/referencetype. I would appreciate any input/advice! 回答1: Cause of this error -You are trying to pass a primitive object into a generic type

Insert Dimensions to complete Expression/ReferenceType

萝らか妹 提交于 2020-11-27 04:41:46
问题 I'm a newbie to Java. I have provided a short snippet from my code for BFS. public int bfs(Person p, Person q) { private HashMap<Person, boolean> marked; private int count; marked = new marked<Person, boolean>(); count = new int; } According to Eclipse, I have an error on each of the last 4 lines. Syntax Error: insert "Dimensions" to complete expression/referencetype. I would appreciate any input/advice! 回答1: Cause of this error -You are trying to pass a primitive object into a generic type

Does Kotlin have primitive types?

人走茶凉 提交于 2020-07-17 11:55:14
问题 Does Kotlin have primitive types?. When I declare the variable: val myAge: Int = 18 then the myAge variable stores the actual values is 18 or stores the addresses of the objects in the memory?. If Int is primitive type then why we can use its method like myAge.minus(10) ? 回答1: No... and yes. Kotlin doesn't have primitive type (I mean you cannot declare primitive directly). It uses classes like Int , Float as an object wrapper for primitives. When kotlin code is converted to jvm code, whenever

GetRef's memory consumption (garbage collection) changed with KB4525236

荒凉一梦 提交于 2020-06-24 22:01:10
问题 We experience out-of-memory issues after installing KB4525236 on our Windows 2016 Servers/Windows 10 Clients. This security fix seems to have changed the moment when memory is garbage collected when calling a function through GetRef . Pré KB4525236 Each instance created in a function called through GetRef got garbage collected as soon as the instance variable was set to nothing Post KB4525236 Each instance created in a function called through GetRef remains in memory and is garbage collected

Reference Types/Subclassing, and Changes to Swift 4 Codable & encoder/decoders

烈酒焚心 提交于 2020-01-24 22:58:07
问题 I'm struggling to understand class/reference type behavior and how this relates to changes as I try to upgrade and reduce code using Codable in Swift 4. I have two classes – a SuperClass with all of the data that will be persistent and that I save to UserDefaults (a place name & string with coordinates), and a SubClass that contains additional, temporary info that I don't need (weather data for the SuperClass coordinates). In Swift 3 I used to save data like this: func saveUserDefaults() {

How can I create an optional DateTime parameter?

夙愿已清 提交于 2020-01-23 04:38:30
问题 I have this function that returns a reference type. Now, this function has two optional parameters both of which are instances of the DateTime class. The function is something like this: public DateTime GetDate(DateTime start = DateTime.MinValue, DateTime end = DateTime.MinValue) { // Method body... } The error from VS is: Default parameter value for 'start' must be a compile-time constant Of course, the error applies to the second parameter and I perfectly understand what is happening. What

Reference to reference in C#?

。_饼干妹妹 提交于 2020-01-12 03:29:32
问题 As we all know, C# classes object are treated as references, so what happens when you pass a reference object as a reference to a method? Say we have: public class A { ... } and then: public void F(ref A a) { ... } Does the compiler find out that a is already a reference type and keep it that way, or he creates a new reference to that object? And what if we have something like this: public void F(ref A a) { F(ref a); } In this code, besides the obvious StackOverflowException , does the