|
I beg to differ, yes the compiler/linker will allocate a function-local static variable outside the function (to keep it alive when the function returns),
but its scope is limited to the function itself, making it inaccessible to
other functions (encapsulation), which is not what you get by declaring
a (static or other) variable outside the function.
So it has a purpose, and I would not mind C# offering the same possibilities.
Luc Pattyn
|
|
|
|
|
Luc Pattyn wrote: I beg to differ, yes the compiler/linker will allocate a function-local static variable outside the function (to keep it alive when the function returns),
but its scope is limited to the function itself, making it inaccessible to
other functions (encapsulation), which is not what you get by declaring
a (static or other) variable outside the function.
That is exactly what I think is the problem. Normally the scope of a variable is consistent with where it's stored, but allowing "local" static variables creates a variable where the scope differs substantially from where it's stored.
This is not encapsulation. That is done on class level, not inside a class.
---
It's amazing to see how much work some people will go through just to avoid a little bit of work.
|
|
|
|
|
I have a name that is in the format: Lastname, Firstname
I want to split this string into two strings.
Example name: Smith, John
The problem is I don't know the length of the name so I'm thinking maybe a Regex that works until it hits the comma then skips the space and takes the rest of the string.
Any help is greatly appriciated.
The only way to speed up a Macintosh computer is at 9.8 m/sec/sec.
|
|
|
|
|
|
No need for a Regex here:
string name = "Smith, John";
string lastname = name.Substring(0, name.IndexOf(',')).Trim();
string firstname = name.Substring(name.IndexOf(',') + 1).Trim();
Or use String.Split .
If you really want to use a Regex, you can use this one: ([^,]+),([^,]+)
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Thank you very much! It works great.
The only way to speed up a Macintosh computer is at 9.8 m/sec/sec.
|
|
|
|
|
Hi All
If I add the child nodes of a tree to an array list at run time then when I close the application and again open the application will that nodes be saved in the arraylist and will be accesible at Form loading or they will be vanished if vanished so how shall i save the child nodes in some sort of file or any thing that my be accesible after reopening the application.
Please note i dont want a database or XML to use here
SAS
|
|
|
|
|
You can use a BinaryFormatter to save your ArrayList as Binary into a file and restore it from there again.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
|
You may want to check out this[^] C# tutorial on network programming to get started.
/ravi
|
|
|
|
|
|
Glad to be of help!
/ravi
|
|
|
|
|
Hi All
The problem is this that I am making a program that will interface with a number of microcontrollers. That microcontroller further works upon three values. the user will send the three values in the form of packet to the microcontroller which will start work. In some step if the management wants to see the progress they will simply access the microcontroller and see the three values in which state they are I want to work upon the packet sending mathod called modbus communiation system do any one have idea about this how to calculate the modbus in C#
SAS
|
|
|
|
|
sajid.salim.khan wrote: do any one have idea about this how to calculate the modbus in C#
Will this[^] link help?
/ravi
|
|
|
|
|
-Does Form.BeginInvoke needs to end with Form.EndInvoke?
-Is it safe to access property or attribute (Text, Color) of Control from thread other than the one that created it? I know that you can't modify it but can you just read it (don't care about dirty read)?
|
|
|
|
|
mikker_123 wrote: Does Form.BeginInvoke needs to end with Form.EndInvoke?
No, because it's the equivalent of Win32 PostMessage() that occurs on the same thread.
mikker_123 wrote: Is it safe to access property or attribute (Text, Color) of Control from thread other than the one that created it?
Not unless you can guarantee that the creator thread will never write to it. Even then, this may cause an exception in code developed using VS2005. (You can disable this exception checking).
/ravi
|
|
|
|
|
|
How to set a value in the "(Default)" registry key.
This code:
key1.SetValue("(Default)","object value");
creates a new key with the same name.
Help me.
Vasildb
|
|
|
|
|
From MSDN:
A registry key can contain one value that is not associated with any name. When this unnamed value is displayed in the registry editor, the string "(Default)" appears instead of a name. To set this unnamed value, specify either a null reference (Nothing in Visual Basic) or the empty string ("") for valueName.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi,
I have a problem in shutting windows down when my thread is running. I am able to shut windows down after I stopped my thread.
I am using VS 2003 C#, and this is happening in Windows application.
What could be the problem?
Could anyone hlep get rid of this?
Thanks in advance.
Muthu.
|
|
|
|
|
Sure! As long as your thread is running, windows will keep waiting for it to end, or it will give you the choice to forcefully "end task".
Another more graceful way is to set MyThread.IsBackground = true . This way it will automatically end when all other foreground threads of your program end.
Regards
|
|
|
|
|
Thanks.
MyThread is a Background thread. i.e. MyThread.IsBackground = true;
But still it prevents me from shutting down windows.
Muthu.
|
|
|
|
|
That's really wiered!! Are you sure there are no other foreground threads active beside that one? Also does your thread keep running after your closed your program normally?
Regards
|
|
|
|
|
I have a child form that acts as a login prompt. When the login button is press it should open up another child form. which process the login information. For some reason i cannot call a child window from a child. Below is what i have (mainFrm being the parent form and functFrm being the other form i'm trying to open).
private void butLogin_Click(object sender, EventArgs e){
mf = new mainFrm();
Functions functFrm = new Functions(user, pass, host);
functFrm.MdiParent = mf;
functFrm.Show();
}
Could someone point me in the right direction. Thanks
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
Try replacing
functFrm.MdiParent = mf;
with
functFrm.MdiParent = Me.MdiParent;
|
|
|
|