|
Hi
When play with string
you must override the string by your change string variable.
what I'm saying
s=s.Remove(3,3);
|
|
|
|
|
|
Override means
for example
string name = string.Empty;
name = "codeproject";
name = name.Remove(2,3);
Console.WriteLine(name);
output:coroject
|
|
|
|
|
I think you meant "overwrite"...
Oh well, semantics schmantics...
|
|
|
|
|
I have posted a sample for your references.
please check that.
|
|
|
|
|
No, that's creating a new instance of an immutable object.
Override has nothing to do with that.
|
|
|
|
|
I found this: http://www.codeproject.com/KB/IP/ListNetworkComputers.aspx on CP but it doesn't work with Mono in Ubuntu (I get a DllNotFoundException). I know there is the static method in the Dns class GetHostEntry (string ip_address) but sometimes it doesn't get the hostname of computers that are on. Is there some other way to get all the hostnames in a network without using an external dll?
I know I can use the code that was used in the mentionned article on Windows computers, but I'd like a method that work work in Ubuntu as well.
|
|
|
|
|
I want to enumerate all form controls on a user control that inherits from another user control (which also has controls on it). Here's some sample code. UserC in this sample is the user control which inherits from the base class user control.
int BindingFlags = Reflection.BindingFlags.Instance | Reflection.BindingFlags.Public | Reflection.BindingFlags.NonPublic;
foreach (System.Reflection.FieldInfo fi in UserC.GetType.GetFields(BindingFlags)) {
object obj = fi.GetValue(UserC);
if (obj != null)
{
try {
obj.Name();
}
catch (Exception ex) {
}
}
}
This will list all the form controls on the UserC class designer but not the base class it inherits from. You can see them all when debugging. What gives?
|
|
|
|
|
How would I add a timer to this? To keep things simple, I have a form with 1 button and 1 textbox. I have a messagebox that pops up when the textbox loses focus ... if the user clicks OK, it does something. However, if the user doesn't click OK within 3 seconds, I need the box to close and do something else. This is for a mobile app using .NETCF 3.5. Here's what I have so far in regards to the messagebox:
private void TextBox1_LostFocus(object sender, EventArgs e)<br />
{<br />
<br />
DialogResult result = MessageBox.show("message text","title",MessageBoxButtons.OK,MessageBoxIcon.None,MessageBoxDefaultButton.Button1):<br />
<br />
if (result == DialogResult.OK)<br />
{<br />
Button1.Focus();<br />
}<br />
else<br />
{<br />
}<br />
}
Any help would be appreciated! Thanks!
|
|
|
|
|
Most likely you'll need to create a Form that looks like a message box that has a timer on it. The built-in MessageBox is not very customizable outside of the text and icons.
|
|
|
|
|
|
|
|
Hi,
why is language that important? to learn concepts just read the text and look at the
program structure and the classes/methods used.
if you can write C# I trust you can also read VB code?
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
I can (sorta) comprehend what the VB code is trying to do, yes.
|
|
|
|
|
Hello,
I have here and than the following Problem:
I have a self-made control in a library that I use in my application. After a while the designer tells me, when I want to open the Form containing the Control, that he cannot convert type 'A' to type 'A', where 'A' is a own class that contains Data that can be changed with the control.
In the InitializeComponent() of the Form there is the call
this.theControl.TheA = ((A)(resources.GetObject("theControl.TheA")));
that I think causes the Problem. As with this the Data is serialized and deserialized, I believe that after changing the library that contains the control this serialize does not work in the same way (maybe the assembly version number is included?).
Is there a way to take control over the storing of complex data to not have it serialized in the .resx file?
Thanks for your help.
Greets
Roland
|
|
|
|
|
You can change the way the designer serializes TheA property by putting the following attribute on TheA property: [DesignerSerializationVisibility(...)]
Beyond that, if you want further control, you may need to have the control implement ISerializable and perform serialization that doesn't care about the version to get around this issue.
|
|
|
|
|
Thank you very much!
Greets
Roland
|
|
|
|
|
I gave up. How can I save back data to app settings. I'm doing it like this..but it's not working:
Configuration configManager = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
ConfigurationSectionGroup section = configManager.SectionGroups["applicationSettings"];
if (section != null)
{
ClientSettingsSection clientSettings = section.Sections["OutlookSync.Properties.Settings"] as ClientSettingsSection;
if (clientSettings != null)
{
SettingElement element = clientSettings.Settings.Get("hello");
element.Value.ValueXml.InnerText = "www";
configManager.Save(ConfigurationSaveMode.Full);
}
}
this is the section I'm trying to read
<br />
<applicationSettings><br />
<OutlookSync.Properties.Settings><br />
<setting name="hello" serializeAs="String"><br />
<value>hello</value><br />
</setting><br />
</OutlookSync.Properties.Settings><br />
</applicationSettings><br />
|
|
|
|
|
Hi,
Are you intending to save settings that are made during the execution of the programme? If so you should be using "userSettings". I think the "applicationSettings" section is intended to be read only and configured at design time or by manually editing the appname.exe.config file but I may be wrong on this.
The default values for user settings are stored in appname.exe.config but runtime changes are saved to user.config which resides deep down in a user's Local Settings directory.
The code to read and write user settings can be as simple as this.
String greeting;
private void ReadSettings() {
greeting = Properties.Settings.Default.hello;
}
private void WriteSettings() {
Properties.Settings.Default.hello = greeting;
Properties.Settings.Default.Save();
}
AlanN
|
|
|
|
|
Hello everyone,
If I am using the ReaderWriterLock class, in the following 3 situations, except performance degrade, are there any functional issues? E.g. deadlock?
1. Acquire a specific write/read lock, and then acquire the write/read lock again, but release the write/read lock twice;
2. Acquire a specific read lock, and then acquire the write lock for the same object, and release in reverse order write lock, then read lock;
3. Acquire a specific write lock, and then acquire the read lock for the same object, and release in reverse order read lock, then write lock.
thanks in advance,
George
|
|
|
|
|
Readers can acquire the lock only if there are no writer threads. You did not specify if you are using AcquireReaderLock or AcquireWriterLock. Anyway if you acquire the lock (reader or writer) and you try to call the Release method twice you'll get an exception.
These operations are exclusive (you have a lock for one or more readers or you have a lock for only one single writer). The AcquireReaderLock, AcquireWriterLock methods supports a timeout value, if the timeout expires an exception is thrown.
From MSDN:
"If the current thread already has the writer lock, no reader lock is acquired. Instead, the lock count on the writer lock is incremented. This prevents a thread from blocking on its own writer lock. The result is exactly the same as calling AcquireWriterLock, and an additional call to ReleaseWriterLock is required when releasing the writer lock."
"AcquireReaderLock supports recursive reader-lock requests. That is, a thread can call AcquireReaderLock multiple times, which increments the lock count each time. You must call ReleaseReaderLock once for each time you call AcquireReaderLock. Alternatively, you can call ReleaseLock to reduce the lock count to zero immediately."
|
|
|
|
|
Thanks Zoltan,
I read the document again. Two more issues
1.
When a thread acquires a read lock, and then upgrade to write lock, the thread is not ensured to continue to hold the lock and proceed executuion, since it will be appended to the end of the write lock queue, and in this scenario a thread which waits for read lock will be awaked, and the awaked thread will hold read lock? Right?
2.
So, if I want a thread to proceed execution and hold lock all the time, I need to let it own write lock at first, other than upgrade?
regards,
George
|
|
|
|
|
When a read lock is upgraded, the write lock request will be placed in the end of queue. So all the read/write locks will be processed before this one gets access.
George_George wrote: So, if I want a thread to proceed execution and hold lock all the time, I need to let it own write lock at first, other than upgrade?
If you want to hold the lock all the time, you should not use ReaderWriterLock class. It is used to support single writers and multiple readers. BTW, why you want to hold the lock all the time ?
Also if you are on .NET 3.5, use ReaderWriterLockSlim which is more efficient than ReaderWriterLock . Many people has reported several drawbacks for ReaderWriterLock .
modified on Thursday, April 17, 2008 1:52 AM
|
|
|
|
|
N a v a n e e t h wrote: It is used to support single readers and multiple writers.
It's the other way around: single writer multiple readers.
|
|
|
|