|
Hello everyone,
In my sample below, abcd is out parameter. I think it only reduces the value copy from input parameter of caller (Main), and it does not reduces value copy from instance returned from DateTime.Now to abcd (assignment), correct?
(in more details when we do assignment abcd = DateTime.Now, a new instance will be created, and value copied from DateTime.Now return instance, and making abcd point to the new instance?)
static void Test2(out DateTime abcd)
{
abcd = DateTime.Now;
}
static void Main(string[] args)
{
DateTime abcd;
Test2(out abcd);
return;
}
thanks in advance,
George
|
|
|
|
|
Why do you keep asking this sort of questions ? Seriously....
As previously discussed, DateTime.Now creates a new value, which is assigned to abcd. out and ref are the same in MSIL, the C# compiler enforces out.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Thanks Christian,
This is not the same as the question I asked before. I just use a common scenario to ask another totally different question.
Christian Graus wrote: DateTime.Now creates a new value
Yes, this is what I understand and we agree. I am not asking this.
What I am asking is how C# will treat with assignment with out variable. In my sample, at least I could think of two scenarios of how C# compiler implements this,
- making out variable pointing to the new instance returned by DateTime.Now directly;
- making a value copy from the new instance returned by DateTime.Now to another new instance, and making abcd pointing to the "another new instance".
Any ideas?
regards,
George
|
|
|
|
|
?You can always read the MSIL to answer these sort of questions. My vote is on option 1, tho.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Thanks Christian!
Here is the IL code I got. I think you are correct. Using stobj will make a value copy, right?
.method private hidebysig static void Test2([out] valuetype [mscorlib]System.DateTime& abcd) cil managed
{
.maxstack 8
L_0000: nop
L_0001: ldarg.0
L_0002: call valuetype [mscorlib]System.DateTime [mscorlib]System.DateTime::get_Now()
L_0007: stobj [mscorlib]System.DateTime
L_000c: ret
}
regards,
George
|
|
|
|
|
George_George wrote: making a value copy from the new instance returned by DateTime.Now to another new instance, and making abcd pointing to the "another new instance".
Why would anyone want to do it this way?
|
|
|
|
|
Thanks Senthil,
Out variable saves value copy on stack if the value type is big.
Anyway, any comments or answers to my original question?
regards,
George
|
|
|
|
|
George_George wrote: Out variable saves value copy on stack if the value type is big.
Yes, it does. I was questioning your 2nd mechanism of implementing of the copy.
And yes, you got it right. out parameters are like pointers in C/C++.
void Method(int *p)
{
int x = 20;
*p = x;
}
void G()
{
int y = 10;
Method(&y);
}
|
|
|
|
|
Thanks Senthil,
1.
Sorry my English is not good. I think you mean out variable only affects function call behavior (passing pointer other than passing a value copy), not affecting assignment, correct?
2.
In my second approach, I mean we can change the pointer value of the out variable passed in, and making the pointer pointed to the instance created by DateTime.Now, so that there is no need to make another value copy from the instance created by DateTime.Now to another instance (and making abcd point to the "another instance"). Have I made myself understood?
regards,
George
|
|
|
|
|
George_George wrote: Sorry my English is not good. I think you mean out variable only affects function call behavior (passing pointer other than passing a value copy), not affecting assignment, correct?
Yes.
George_George wrote: no need to make another value copy from the instance created by DateTime.Now to another instance (and making abcd point to the "another instance")
Yes.
|
|
|
|
|
Thanks Senthil,
Question answered.
regards,
George
|
|
|
|
|
George
As CG said, you are asking a lot of similar questions. Perhaps now would be a good time to start reading/studying/learning the C# and CLR Emca specifications. If it is plentiful, unambiguous information you are after (who isnt? ), then that would be a good too look at. Chances are better to get the correct answer there, than simply relying on word of mouth.
Cheers
leppie
|
|
|
|
|
Hi,
I have a requirement for a project to have a button on a webform which once pressed will switch to a running Winforms app (not in .NET) and send keys e.g. Alt S. I imagine that this is going to require ActiveX, can someone just confirm that this is the correct approach?
Thanks
|
|
|
|
|
willybt88 wrote: to a running Winforms app (not in .NET)
This is a contradiction. WinForms is .NET. What language is your Win32 app then ?
willybt88 wrote: I imagine that this is going to require ActiveX, can someone just confirm that this is the correct approach?
If you're going to send it to an app running on the client, ActiveX is your best bet, yes.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
hi,
I'm trying to use a regular expression to find all data following two blank lines.
this means there should be two newline formatters preceeding all data I want to find. therefore I've been trying something like:
(?<=\n\n).*
somehow I need to check the lines are indeed blank with only newline formatters and then return the text following the two new lines.
no luck though. any ideas?
thanks,
Stephen
|
|
|
|
|
Well, it's \n\r ( or \r\n, I forget, I use Environment.NewLine instead ).
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi
i want to send message to other clients via MSMQ by this path :
[clientName]\Private$\Orders
but the followinng error has shown me :
Invalid queue path name
but if i use . (dot) as follow :
.\Private$\Orders
my queue was successfully created, where does my problem and how to solve it ?
i'm also get the following error when use this path :
FormatName:Direct=OS:[myMachineName]\private$\remote
error :
Can not create a queu with the path FormatName:Direct=OS:[myMachineName]\private$\remote
thanks
modified on Sunday, June 15, 2008 5:50 PM
|
|
|
|
|
Hey.
I've been trying to get this to work but with no avail. I'm trying to modify a GraphicsPath to remove a line or move it so it matches the situation i'm using.
I'm using it as part of a new Rendering mode (for the ToolStripManager.Renderer), and i've got a code that creates a path (and adds curves to the corners if I want it to).
My code gets the GraphicsPath of the AffectedArea of a MenuStrip dropdown (or ToolStripDropDownButton). I want the code to remove or alter the line to leave a space for the ConnectedArea section.
Here's a picture of the area, I mean, that I want to be able to remove (opens in new window)
The black border is the GraphicsPath lines that the code retrieves. The red part is the part of the line I want to remove.
Here's a sample of the code inside OnRenderToolStripBorder(ToolStripRenderEventArgs e)
if (e.ToolStrip is ContextMenuStrip || e.ToolStrip is ToolStripDropDownMenu)
{
Rectangle Area = new Rectangle(0, 0, e.AffectedBounds.Width - 1, e.AffectedBounds.Height - 1);
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
using (GraphicsPath Path = CreateDrawingPath(Area, 0))
{
e.Graphics.DrawPath(Pens.Black, Path);
}
}
I've tried using:
Path.PathPoints[0] = new PointF(e.ConnectedArea.Width, 0);
To try and change the first point of the GraphicsPath to start from the X axis of the width of the ConnectedArea (the GraphicsPath goes "Left-top" -> "Right-top", "Right-top" -> "Right-bottom" etc).
But it doesn't work. Does anyone have an idea how I might be able to move the first point to where the ConnectedArea Width ends?
Thanks in advance
|
|
|
|
|
Hi,
I have an application basically written in VS 2003, then I upgraded to 2005, now I'm running 2008 and I cant use any of the .Net 3 components so please tell me how to upgrade my app to be .Net 3 compatible
Thank you guys!
All generalizations are wrong, including this one!
(\ /)
(O.o)
(><)
|
|
|
|
|
I don't see why you can't, there's no such thing as a .NET 2.5 project, your project is .NET 3.5 ( not 3.0 ) or it's not.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi Christian,
It's good to see you , I always get optimistic when the answer is from you
You see, I had to use the element host thing to include some wpf controls but i just cant reference any of the .net 3 dlls when it's not the case when i create a new app in .net 3/3.5
i'm sure i just need to find a way to convert my whole app to support .net 3/3.5 but i dont know how to do it, there should be some tool somewhere withing the ide i suppose
All generalizations are wrong, including this one!
(\ /)
(O.o)
(><)
|
|
|
|
|
It seems probable to me that your project did not include references to the .NET 3 dlls, and you just need to add those references.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Christian Graus wrote: ..references to the .NET 3 dlls, and you just need to add those references.
I thought so too at first but it's not possible when the project is not based on .Net 3 framework from the moment it is created!
You just cant include any dll with the version 3.x.x as it will be disabled!
Please try now to see what I mean, I'm sure you will be surprised as I am now
Create a new solution based on a version less than 3 and try to reference anything from .Net 3.
All generalizations are wrong, including this one!
(\ /)
(O.o)
(><)
|
|
|
|
|
Oh - there's a setting in 2008 that sets what framework you're building against, it DOES support 2.0. Perhaps the conversion is set to that by default, and you need to change that in the project settings ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|