|
Oops. My bad. Guess I shouldn't be typing answers late in the night. Yes, it should be 5,5 and 5,2. Well, if it is what you expected, why do you say string is treated like a value type? Only because Test is a reference type, setting t.x = 2 in Foo() changed the value (after commenting out t = new Test());
Regards
Senthil
|
|
|
|
|
Let me frame my doubt with the following code.
using System;
class Test
{
public static void Append(string strParam)
{
strParam = strParam + " - C#";
}
public static void Main()
{
string strMsg = "Hello World";
Console.WriteLine (strMsg);
Append(strMsg);
Console.WriteLine (strMsg);
}
}
Here a string strParam is being passed to Append(). Since string is a reference type, I would expect strParam to refer to the same string object to which strMsg is a reference. Hence as per my expectation on calling Append() the string " - C#" should get appended to the same string object to which strMsg is referring and it should become "Hello World - C#". But to achieve this behavior we have to make strParam as "ref".
I am unable to find justification to this behavior of string.
Thanks in advance
Siddhartha
|
|
|
|
|
What I'm trying to explain is that the behavior is how reference types work, not just string. Try doing it with your own class and you'll see it is true. In the previous example I gave, that's why when t = new Test() executed, the value of t.x did not change in the caller.
If your argument is correct, then
<br />
string x = "Hello World";<br />
string y = x;<br />
y = "Bad Boy";<br />
the last statement should change x too, I hope you agree that's not logical or intuitive. I hope you are not confusing with C++ references, which, by the way, behave as you said.
Think of references as pointers in C/C++. Take a pointer, say, int *p.
<br />
int x = 20;<br />
int *p = &x;<br />
int *z = p;<br />
int y = 70;<br />
*z = 50;
z = y;
It's the same way references operate. If you call a function passing a reference type, the *reference* gets passed by value, so if you try to change what the variable refers to, it won't affect the caller. But still because they both point to the same object, if you attempt to modify the object referred to, the caller will see the change.
Hope this helps.
Regards
Senthil
|
|
|
|
|
Thanks,
I now have a better insight of C# strings
|
|
|
|
|
Hi everyone,
Know of any vertical progress bar for .NET or how to create one? Any help is good. Thanks.
It is not the length of time, but what you plan to do with the time given to you that matters.
|
|
|
|
|
Search the articles here on CodeProject. There are some that cover this subject.
www.troschuetz.de
|
|
|
|
|
i have 3 forms 1 is MDIContainer that is mdiparent and remaining 2 are chiles i.e. Child1,Child2
if i want to open childs in mdi i have to write in mdiparent
Child1 obj = new Child1();
obj.Show();
obj.MdiParent = this;
suppose is want to open Clild2 on click of button on child1
so i have to write code
Child2 obj = new Child2();
obj.Show();
but it open in new it doesn't have any parent
i want that it open in mdiparent as a child
so i try
Child2 obj = new Child2();
obj.Show();
midparent par = new mdiparent()
obj.MdiParent = par;
but it is not possible to create object and specify child2 to mdiparent is mdiparent
any another way
please post as early as possible
thank you
Hemant
|
|
|
|
|
If child1 was created as an MDI child, then it's MDIParent property can be used.
In your Child2 code, you should be able to do the following:
Child3 frm3 = new Child3();
frm3.MdiParent = this.MdiParent;
frm3.Show();
Cheers,
Simon
sig :: "Don't try to be like Jackie. There is only one Jackie.... Study computers instead.", Jackie Chan on career choices.
article :: animation mechanics in SVG blog:: brokenkeyboards "Most of us are programmers, but a few use VB", Christian Graus
|
|
|
|
|
What is the way to deactivate the keyboard while my richTextBox is being updated?
|
|
|
|
|
While there are a few ways ranging from overriding ProcessDialogKey and doing nothing while a state variable is set to P/Invoking SetWindowsHookEx and writing an extremely efficient and robust keyboard hook, the most simple way is to set RichTextBox.Enabled to false . The point of disabling a control is to disable input into that control.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
The ValueChanged event of the NumericUpDown control is not fired when the user changes its value, by typing in the text part of it;
Though it should be, as documented in MSDN.
(it is only fired when the user clicks the up and down arrows)
How can I make it to be fired?
Lizzy
|
|
|
|
|
It should be fired when the control loses focus. Until the control loses focus the value is not actually changed when editing it manually. If this wasn't the case, if you mean to type 90 and the event fired when you typed just 9, bad things could happen that the developers using the control may not expect.
If this is the behavior you want, try extending the control and overriding ProcessDialogKey or ProcessDialogChar and fire the event yourself, or use a timer to fire the event after a short amount of time (enough to give moderately slow typers time to enter 2 or more digits - whatever it is you're expecting).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
how to set an edit box control so that it only receive numbers. I was thinking about using the event key press.
<italic>Work hard and a bit of luck is the key to success. You don`t need to be genius, to be rich.
|
|
|
|
|
you are taling about windows base application or webbased application?
|
|
|
|
|
It`s windows base application.
<italic>Work hard and a bit of luck is the key to success. You don`t need to be genius, to be rich.
|
|
|
|
|
sorry for posting again :
if its web based then try this ..
//client side code ...
function ValidateNum(input,event){
var keyCode = event.which ? event.which : event.keyCode;
if(parseInt(keyCode)>=48 && parseInt(keyCode)<=57){
return true;
}
return false;
}
at server side page load event
write
yourtextboxname.Attributes.Add("onKeyPress","return ValidateNum(this,event)");
|
|
|
|
|
Handle the KeyPress event and set KeyPressEventArg's Handled property to true if the character is non-numeric.
|
|
|
|
|
Just as Font.Height property gets the line spacing, in pixels, of the given font, how to calculate the same when we have an image instead of a text between two lines.
i.e if we insert an image in any document one after another in consecutive lines there is some space between two images. How to get that value ?
---------------------------------------- line 1
(^o^)/ my image
---------------------------------------- line 2
please guide
|
|
|
|
|
here is what I have:
<br />
private frmMain ParentForm<br />
{<br />
get{return (frmMain)this.MdiParent;}<br />
}<br />
<br />
private void frmEventList_Load(object sender, System.EventArgs e)<br />
{<br />
ParentForm.StatusBar = "Searching for events";
LookupEvents(DateTime.Now, DateTime.Now);<br />
ParentForm.StatusBar = "Ready222";<br />
}<br />
using this the Parent forms status bar text does not change. No exception is thrown indiciating that there is somthing wrong with the code. I have just recently had to change over from VB.NEt so it may be something simple.
Thanks for the help
|
|
|
|
|
are u sure ur frmEventList_Load is getting callled? Try putting a break point in the event handler and following ur code. U should see where ur code is failing to do what u expect. What u've posted looks fine but we're missing a lot more that could be wrong.
|
|
|
|
|
I have put the line break in the load event. It steps through fine, but when I call on the StatusBar property in the commend window it says:
error: 'ParentForm.StatusBar' does not exist
but how would the parent mdiForm not exist? Thanks for the help.
|
|
|
|
|
Could you please post the code where u are creating and showing the MdiChild?
|
|
|
|
|
Here is the form load for the mdiParent
<br />
private void frmMain_Load(object sender, System.EventArgs e)<br />
{<br />
StatusBarPanel status = new StatusBarPanel();<br />
status.AutoSize = StatusBarPanelAutoSize.Spring;<br />
sbrStatus.Panels.Add(status);<br />
sbrStatus.ShowPanels = true;<br />
<br />
Form frmEventList = new frmEventList();<br />
frmEventList.MdiParent = this;<br />
frmEventList.WindowState = System.Windows.Forms.FormWindowState.Maximized;<br />
frmEventList.Show();<br />
}<br />
Thanks for the help
|
|
|
|
|
I cant see what is wrong with ur code...at least not to the point where the command line would give u the error ur stating, unless ur querying ParentForm.StatusBar when its out of scope although I doubt that. Whats even wierder is that, if I'm not misunderstanding, when ur application runs, your not getting any exception.
Just to cover all possibilities, I'll ask u to post some more code once again...sorry :p :
Please post ur StatusBar property.
|
|
|
|
|
I have a windows form, with a data grid on it, that contains information pulled from an xml file. I want to be able to detect if anything in the datagrid is edited, but I do not know what the event is called. Thus, if they add a row, edit a cell, or delete a row, I will set a bool variable (isChanged = true). Any help on what the event is called or how this can be acomplished will be appreciated. Thank you.
Keith
|
|
|
|