pass-by-reference

How to use a .NET method which modifies in place in Python?

大城市里の小女人 提交于 2019-12-18 04:22:18
问题 I am trying to use a .NET dll in Python. In a .NET language the method requires passing it 2 arrays by reference which it then modifies: public void GetItems( out int[] itemIDs, out string[] itemNames ) How can I use this method in Python using the Python for .NET module? Edit: Forgot to mention this is in CPython not IronPython. Additional info. When I do the following: itemIDs = [] itemNames = [] GetItems(itemIDs, itemNames) I get an output like: (None, <System.Int32[] at 0x43466c0>,

C# Pass a property by reference

隐身守侯 提交于 2019-12-18 03:06:47
问题 Is there anyway to pass the property of an Object by reference? I know I can pass the whole object but I want to specify a property of the object to set and check it's type so I know how to parse. Should I maybe take another approach (I cannot change the original object in anyway)? public class Foo{ public Foo(){} public int Age { get; set; } } private void setFromQueryString(object aProperty, String queryString, HttpContext context) { //here I want to handle pulling the values out of //the

Overloading reference vs const reference

ⅰ亾dé卋堺 提交于 2019-12-18 02:49:40
问题 I have the following code: #include <iostream> template <typename T> void f(T& x) { std::cout << "f(T& )" << std::endl; } template <typename T> void f(const T& x) { std::cout << "f(const T& )" << std::endl; } int main() { int a = 0; const float b = 1.1; f(a); // call f(T&) f(b); // call f(const T&) } The output is: f(T& ) f(const T& ) My question is: how does the compiler know which function to call? If I remove the references from the function definitions then I get an "ambiguous call" type

Is Objective-C pass-by-value or pass-by-reference?

混江龙づ霸主 提交于 2019-12-18 00:29:26
问题 Since we always use pointers to define variables, I was wondering if Objective-C is "pass by value", since like Java, the actual value would be passed by using its reference. However, since it seems to be built up on top of C, would it have all the functionality of C? 回答1: C does not support pass-by-reference and Objective-C, being a strict superset of C doesn't either. In C (and Objective-C) you can simulate pass-by-reference by passing a pointer, but it's important to remember that you're

How does the C# garbage collector find objects whose only reference is an interior pointer?

旧城冷巷雨未停 提交于 2019-12-17 23:09:37
问题 In C#, ref and out params are, as far as I know, passed by passing only the raw address of the relevant value. That address may be an interior pointer to an element in an array or a field within an object. If a garbage collection occurs, it's possible that the only reference to some object is through one of these interior pointers, as in: using System; public class Foo { public int field; public static void Increment(ref int x) { System.GC.Collect(); x = x + 1; Console.WriteLine(x); } public

“ref” keyword and reference types [duplicate]

吃可爱长大的小学妹 提交于 2019-12-17 21:05:08
问题 This question already has answers here : What is the use of “ref” for reference-type variables in C#? (10 answers) Closed 6 years ago . someone in my team stumbled upon a peculiar use of the ref keyword on a reference type class A { /* ... */ } class B { public void DoSomething(ref A myObject) { // ... } } Is there any reason someone sane would do such a thing? I can't find a use for this in C# 回答1: Let class A { public string Blah { get; set; } } void Do (ref A a) { a = new A { Blah = "Bar"

Passing optional parameter by reference in c++

大憨熊 提交于 2019-12-17 15:38:43
问题 I'm having a problem with optional function parameter in C++ What I'm trying to do is to write function with optional parameter which is passed by reference, so that I can use it in two ways (1) and (2), but on (2) I don't really care what is the value of mFoobar . I've tried such a code: void foo(double &bar, double &foobar = NULL) { bar = 100; foobar = 150; } int main() { double mBar(0),mFoobar(0); foo(mBar,mFoobar); // (1) cout << mBar << mFoobar; mBar = 0; mFoobar = 0; foo(mBar); // (2)

Passing By ref and out

偶尔善良 提交于 2019-12-17 10:57:19
问题 So if I am iterating using a foreach loop and I have a function inside that takes an argument of the object iterated from list, and lets say i set its value to be different. Why don't I have to use out or ref ? I thought it was only passed by value if it you didn't use out or ref.... I know that a ref you must have initialized the variable before and out you just have to have set its value before return from the method. It seems like if you a iterating thru a list and pass an object in its

C++: Why pass-by-value is generally more efficient than pass-by-reference for built-in (i.e., C-like) types

北城余情 提交于 2019-12-17 09:39:58
问题 just as what indicated in the title 回答1: A compiler vendor would typically implement a reference as a pointer. Pointers tend to be the same size as or larger than many of the built-in types. For these built-in types the same amount of data would be passed whether you passed by value or by reference. In the function, in order to get the actual data, you would however need to dereference this internal pointer. This can add an instruction to the generated code, and you will also have two memory

Java is NEVER pass-by-reference, right?…right? [duplicate]

不想你离开。 提交于 2019-12-17 09:09:37
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Is Java “pass-by-reference”? I found an unusual Java method today: private void addShortenedName(ArrayList<String> voiceSetList, String vsName) { if (null == vsName) vsName = ""; else vsName = vsName.trim(); String shortenedVoiceSetName = vsName.substring(0, Math.min(8, vsName.length())); //SCR10638 - Prevent export of empty rows. if (shortenedVoiceSetName.length() > 0) { if (!voiceSetList.contains("#" +