namespace WindowByRef
{
class Window
{
public Window(int x, int y)
{
this.x = x;
this.y = y;
}
protected int x;
protected int y;
public void Move(int x, int y)
{
this.x = x;
this.y = y;
}
public void ChangePos(ref int x, ref int y)
{
this.x += x;;
this.y += y;
x = this.x;
y = this.y;
}
}
class TestWindowByRef
{
public static void Main()
{
Window wnd = new Window(5, 5);
int x = 5;
int y = 5;
wnd.ChangePos(ref x, ref y);
Console.WriteLine("{0}, {1}", x, y);
x = -1; // i would expect that x here is 10 -1 not 5 -1 but its 5 -1 or x =
this.x; in ChangePos not affect outside
y = -1;
wnd.ChangePos(ref x, ref y);
Console.WriteLine("{0}, {1}", x, y);
}
}
}
can someone just explain me this
thx 4 1135
On Nov 23, 11:31 am, Gigs_ <g...@hi.t-com.hrwrote:
<snip>
can someone just explain me this
It's not at all clear why you'd expect it to be 10-1 - it will be 10
before the assignment, and -1 after the assignment. When I run your
code, it outputs;
10, 10
9, 9
which is just what I'd expect. What are you seeing, and what would you
expect to see?
Jon
Can you clarify what behavior you were expecting?
I'll treat x & y the same, since you do the same to both;
You start at 5
You call ChangePos passing 5, which moves the window to 10, and update
the ref-variable to this value: 10
Output 10
You set the variable to -1
You call ChangePos passing -1, which moves the window to 9, and update
the ref-variable to this value: 9
Output 9
---
Is this not what you are seeing?
Marc
Jon Skeet [C# MVP] wrote:
On Nov 23, 11:31 am, Gigs_ <g...@hi.t-com.hrwrote:
<snip>
>can someone just explain me this
It's not at all clear why you'd expect it to be 10-1 - it will be 10
before the assignment, and -1 after the assignment. When I run your
code, it outputs;
10, 10
9, 9
which is just what I'd expect. What are you seeing, and what would you
expect to see?
Jon
sorry for your time. maybe my brain didn't work last few hours
;-)
Marc Gravell wrote:
Can you clarify what behavior you were expecting?
I'll treat x & y the same, since you do the same to both;
You start at 5
You call ChangePos passing 5, which moves the window to 10, and update
the ref-variable to this value: 10
Output 10
You set the variable to -1
You call ChangePos passing -1, which moves the window to 9, and update
the ref-variable to this value: 9
Output 9
---
Is this not what you are seeing?
Marc
thx i figure it. i was looking at x=-1 but i sow x-=1 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Zlatko Matić |
last post by:
Let's assume that we have a database on some SQL server (let it be MS SQL
Server) and that we want to execute some parameterized query as a
pass.through query. How can we pass parameters to the...
|
by: Mark |
last post by:
I created a test to check the execution time difference between executing a
SQL Server stored procedured using explicit parameters versus not. In one
case I created new SqlParameters in the code,...
|
by: Tim::.. |
last post by:
Can someone tell me a better way or give me a link that shows a better way to
create large numbers of SQL parameters...
Example... A better way to write this code!
<code>
Sub...
|
by: cody |
last post by:
I got a similar idea a couple of months ago, but now this one will require
no change to the clr, is relatively easy to implement and would be a great
addition to C# 3.0 :)
so here we go..
To...
|
by: John Friedland |
last post by:
My problem: I need to call (from C code) an arbitrary C library
function, but I don't know until runtime what the function name is,
how many parameters are required, and what the parameters are. I...
|
by: Hexman |
last post by:
Hello All,
Well I'm stumped once more. Need some help. Writing a simple select and update program using VB.Net 2005 and an Access DB. I'm using parameters in
my update statement and when trying...
|
by: pamelafluente |
last post by:
Hi guys,
In the past I have used several time optional parameters in my
function.
But Now I am more inclined to think that they are more dangerous than
useful, and probably better to be...
|
by: John Kotuby |
last post by:
Hi all,
I am working on porting an application from VB6 to VB.NET 2003 and am
running into some problems. When declaring and populating the parameters for
a SQL Stored Procedure by using the...
|
by: Xah Lee |
last post by:
In this article, i explain how the use of bit masks is a hack in many
imperative languages.
Often, a function will need to take many True/False parameters. For
example, suppose i have a function...
|
by: Jared Grant |
last post by:
I am trying to find the value from some output parameters from a stored procedure. I have tried several different methods but somehow cannot get it to work. here is my source code:
dim dr as...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |