pass-by-value

C# passing parameter (value or reference)?

夙愿已清 提交于 2019-12-11 13:43:59
问题 I've been told that when you pass an Object to a method, it's passed "by value". I made a little test to examine it: Point p = new Point(1, 1); Circle c = new Circle(p); p.x = 999; Console.WriteLine(c.p.x); the code above prints "999", but I thought the object is copied to the method I've been told that if you're not using "ref" (or "out") the method get the value of the object. can someone make it clear to me? thanks, socksocket 回答1: Assuming Point is declared as class, not p itself is

Why does java use both pass-by-value and pass-by-reference? [duplicate]

纵饮孤独 提交于 2019-12-11 11:35:43
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: Is Java “pass-by-reference”? Maybe I'm missing something...but I can't really understand why Java uses both the pass-by-value and pass-by-reference. Why not using only one paradigm? 回答1: It doesn't. Java is purely pass-by-value. The value passed when you're dealing with an object is an object reference, but that has nothing to do with "pass by reference." Pass-by-reference means that a function can be passed a

DataBinding DropDownList in C#/ASP.NET

自闭症网瘾萝莉.ら 提交于 2019-12-11 07:36:04
问题 I have a search.aspx page that has this: <asp:DropDownList id="ddlPopulation" runat="server" DataTextField="population" DataValueField="pid"> </asp:DropDownList> I then have a data bind on page_load: StringBuilder sql = new StringBuilder(); // Define sql sql.Append("SELECT pid, population "); sql.Append("FROM populations "); sql.Append("ORDER BY pid ASC "); IDataReader reader = SqlHelper.GetDataReader(sql.ToString()); ddlPopulation.DataSource = reader; ddlPopulation.DataBind(); How do I: Add

Is there simple PHP code to distinguish “Passing the object as reference” vs “Passing the object reference as value”?

淺唱寂寞╮ 提交于 2019-12-11 07:17:18
问题 This is related to question: How does the "&" operator work in a PHP function? Is there simple code to show the difference between passing the object as reference vs passing the object's reference as value? 回答1: You can pass a variable to a function by reference. This function will be able to modify the original variable. You can define the passage by reference in the function definition: <?php function changeValue(&$var) { $var++; } $result=5; changeValue($result); echo $result; // $result

References in Java

╄→гoц情女王★ 提交于 2019-12-11 05:01:54
问题 i was reading about how you can only pass by value in java and that the only way to swap the contents of two objects is by putting then in an array...passing the reference to the array object by value and then using that reference to swap 0-1 array location. But i have a further question on this: Suppose i create an array such as: List<Integer> array = new ArrayList<Integer>(); Integer a = new Integer(1); array.add(a); So my question is when i "add" an object to an array (in this case Integer

Passing object reference to a method [duplicate]

ぐ巨炮叔叔 提交于 2019-12-11 03:28:37
问题 This question already has answers here : Is Java “pass-by-reference” or “pass-by-value”? (86 answers) Closed 5 years ago . If the Employee reference is made null in the changedetails(), variable id value is retained and NullPointerException is not thrown (Code 1) may be because we just pass a copy of object's reference, but in Code 2 why the variables value has changed Code 1: public class JavaPassing { public static void changedetails(Employee e) { e=null; } public static void main(String

Why this Ruby method passes it's argument by reference

落爺英雄遲暮 提交于 2019-12-11 02:21:20
问题 I answered on this question and stumbled on something strange. Ruby passes its arguments by value, the variables itself are references though. So why the first methods seems to pass its parameter by reference ? require 'set' require 'benchmark' def add_item1!(item, list) list << item unless list.include?(item) end def add_item2(item, list) list |= [item] end def add_item3(item, list) set = Set.new(list) set << item list = set.to_a end array1 = [3,2,1,4] add_item1!(5, array1) p array1 # [3, 2,

Cannot Modify Return Value because It is not a Variable

帅比萌擦擦* 提交于 2019-12-11 00:18:07
问题 Pass by Value strikes again!! player.Vector.X += player.Speed * (float)gameTime.ElapsedGameTime.TotalSeconds; does not work. Vector2 v = player.Vector; v.X -= player.Speed * (float)gameTime.ElapsedGameTime.TotalSeconds; player.Vector = v; fixes this problem. This is explained here: Can't modify XNA Vector components The answer was very well explained and works just fine, but it has been 4 years since it was posted. My question is, since its been 4 years, is there a better way to fix this

Pass values from BackgroundWorker DoWork to BackgroundWorker Completed

情到浓时终转凉″ 提交于 2019-12-11 00:04:38
问题 How do I pass a value from BackgroundWorker DoWork to BackgroundWorker Completed ? Since BackgroundWorker Completed is not called by BackgroundWorker DoWork I am not sure how to do this except declare a public variable . Essentially, I want BackgroundWorker Completed to accept through ByVal a variable from BackgroundWorker DoWork . 回答1: When you declare your DoWork function, note that it has some handy arguments built in : Private Sub backgroundWorker1_DoWork(sender As Object, e As

c++ copy construct parameter passed by value

你说的曾经没有我的故事 提交于 2019-12-10 18:48:52
问题 I want freeFunct to do non const stuff on its own copy of object a. Let's say that freeFunct is required to be a free function because in real code cases it takes many different parameters, calls several public functions from all of them and there is no point in making it a non-static member function of any class. Three different ways of declaring it come to my mind. I have the feeling that the third solution is the worse. Is there any difference between the first two? Is there something