|
The first 'i' is not out of scope of the second i. When a variable is declared in a foreach/for loop it is the same as the following.
int i;
for ( i=0; i++; i<5 )
{
}
The scope of the variable is outside of the loop.
|
|
|
|
|
You're not allowed to do this:
int i = 5;
if (x==0)
{
int i = 7;
}
because the second one 'hides' the first. The compiler isn't smart enough to let you define a second i after the one in a loop, it just works out that you have one in an inner scope, and one in an outer scope. If you put the int i = 5; inside another scope, so that there was no chance of it to flow down, then the compiler would be fine.
Something like this
int i = 0;
for(;i
|
|
|
|
|
P.S. why is this site so hard to use ? I've tried to post this three times and got three different error messages.
Yeah, the server is down quite often lately. Either it's a "Service unavailable", "500 error" or I can't even connect to codeproject.com at all
modified 12-Sep-18 21:01pm.
|
|
|
|
|
The load balancing portion of CodeProject isn't working properly at the moment. Chris is working on the issue...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
CG, use secure.codeproject.com for now. Much more performant and zero timeout errors.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Bought a House!
Judah Himango
|
|
|
|
|
Cool - thanks for the tip. I was expecting you to have explained why my answer was wrong :P
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
This is great!
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hello,
I want to launch numerous Window Applications from a MAIN window which will contain the list of all posible functions the user can perform. Similar to Microsoft Solomon layout. Solomon has the main window with list of functions, and the user can launch any of them, and interact with the windows separetly. I think threading is the way to go here, and how can I achieve that using threading?
Thank you.
|
|
|
|
|
Why don't you just create new child forms? They will be fully functional just as if they were seperate applications. If you just use Show(), they will be modeless so all are running at once.
|
|
|
|
|
Hi All,
I want to display different icon overlays for files and folders
depending on their state.I know how to add icon overlay but my problem
is how i can add more than one icon overlays .I have searched in
groups including this one also but the point was not clear to me. if i
want to add different icon overlays like tortoise svn then whether i
have to implement different icon overlay handlers (seperate dlls) or it
can be done by one executable itself.I have looked in the registry and
toroise svn uses 7 different guid for 7 different icon overlays but on
having a look on there code
http://www.koders.com/cpp/fid177A0F35D08F35B05D2783D4504BF24B4CE88EF2...
does not suggest using different executables as i use C# so i did not
get how they are doing it.atleast they are not using seperate dlls.any
suggestion is most welcome.Thanks.
Rakesh
|
|
|
|
|
in your IShellIconOverlayIdentifier.GetOverlayInfo method you need to return the path to the icon overlay and you should set the flags that prevent it being cached so that each call can return a different path and thus show a different icon. If you read the PSDK docs on the interface it tells you how to do this.
|
|
|
|
|
I'm getting confused between IconHandler and IconOverlay aren't i. Handlers let you stop the caching, overlays don't. You get exactly one overlay per object any duplications being handled by the priority flag and call ordering. In order to get a different overlay you should just be able to return a different icon or offset into the icon resource assembly and it'll work. However be aware that the shell only allows a total of 16 overlay icons so if y ou've already got the system ones and the tortoise ones present you may well run out if you use any more.
|
|
|
|
|
HI ALL,
I have a form with one user defined control (eg text box).I want to capture the lost focus event of that control when user clicks on anywhere on form or menu bar.The default behaviour of LostFocus/Leave event is that it fires when any other contro get focus.But when we click on form or menu the control will not lostfocus thats y LostFocus event for that control doesnt fire at all.
But I want to capture that event when user clicks anywhere on form not at any specific control.How can I do that.PLS HELP..
Regards
|
|
|
|
|
try validate event
"Not everything that counts can be counted..."
-Albert Einstein
|
|
|
|
|
Hi,
Can anyone let me know, How to get information about what are all the objects created at runtime using c#.net
Thanks,
Kiran.
|
|
|
|
|
I use the ANTS profiler. It costs money but I've found it is worth it. You can run a trial version.
|
|
|
|
|
.Net Memory Profiler from SciTech is also worth a look.
|
|
|
|
|
Hi!
I'm using a PropertyGrid in my Options-Dialog, which shows DropDown-ComboBoxes amongst others. The whole thing should be multilingual (no problem due to codeproject).
The problem with the ComboBox is the following: As return-value i don't want the selected text but a nr (like SelectedItem). The ComboBox is realised the following way:
C#-Code:
public class LogDataSettingsConverter : StringConverter<br />
{<br />
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)<br />
{<br />
return true;<br />
}<br />
<br />
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)<br />
{<br />
return true;<br />
}<br />
<br />
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)<br />
{<br />
String[] values = new string[5];<br />
values[0] = "Delete nothing";<br />
values[1] = "Delete logdata";<br />
values[2] = "Ask user";<br />
values[3] = "Delete alarm flag";<br />
values[4] = "Delete logdata and alarm flag";<br />
<br />
return new StandardValuesCollection(values);<br />
}<br />
}<br />
And the according property:
C#-Code:
[CategoryAttribute("GPS/GSM/ID settings"), BrowsableAttribute(true),<br />
TypeConverter(typeof(LogDataSettingsConverter))]<br />
public String DeleteLogMethod<br />
{<br />
get { return deleteLogMethod; }<br />
set { deleteLogMethod = value; }<br />
}
There's another question according to the PropertyGrid:
Is there a posibility to hide specific properties of the PropertyGrid at runtime (maybe by setting the BrowsableAttribute dynmically at runtime)?
Because the "mighty" of the PropertyGrid i think that this should be possibly, but unfortunately i couldn't find anything corresponding!
thanks, greets
mike
ps.: A little Screenshot from my PropertyGrid:
PropertyGrid
|
|
|
|
|
Hi,
I created a new control in C# and it generated additional code. I'm not sure of the importance of thise code, and can't seem to find anything on the MSDN library. Must I keep it in? Or can I delete it?
If you have any interesting articles on this, please let me know.
The automaticaly generated is:
[DefaultProperty("Text"),
ToolboxData("<{0}:VesuviusNavMenu runat=server></{0}:VesuviusNavMenu>")]
[Bindable(true),
Category("Appearance"),
DefaultValue("")]
I hope someone can help.
Regards,
Brendan
|
|
|
|
|
Hi,
Does C# have similar methods to VB's Right and Left methods/functions?
Lets say I have the following:
string myName = "codeproject";
I need the first (left) 2 and last (right) 2 characters of this string. What I tried was the following, but somehow it feels that there are maybe better ways of doing it:
int start = myName.Length-2;
Response.Write(myName.Substring(5, 2));
Please can someone help.
Regards,
Brendan
|
|
|
|
|
Substring is all you have, I believe.
|
|
|
|
|
This is truly a wierd phenomenon. So I have this service that is going to backup files in realtime that get dumped into folders specified by the user. The user specifies various information for this service to use through a Windows.Forms GUI. That GUI uses a BinaryFormatter to both serialize the data into a file when the user exists the GUI, and deserialize that data when the GUI is opened again to load the data into the GUI. This works fine...no errors and it functions as expected.
So I need my service to deserialize the same information from the file so it can do its thing given the settings the user set up right? Well I use practically the same approach that I used for the GUI, but in the service for some reason there is an explicit cast that causes a InvalidCastException to be thrown at runtime...This SAME cast does not throw an exception in the Forms GUI. Any ideas? Here is two snippets of code from the GUI and the Service. The explicit cast that causes the problem in the Service but not the GUI is the cast from the object "item" to an object of type OffSiteBackupServiceNamespace.Location.
Note: fs is a filestream linked to the data file generated by the GUI
GUI code (no compile time or run time errors):
<br />
Object item = formatter.Deserialize(fs);<br />
...<br />
if(item.GetType().ToString().Equals("OffSiteBackupServiceNamespace.Location"))<br />
{<br />
locations.Add((OffSiteBackupServiceNamespace.Location)item);<br />
addLocationSaveToView();<br />
}<br />
Service code (no compile time errors, throws runtime InvalidCastException):
<br />
Object item = formatter.Deserialize(fs);<br />
...<br />
if(item.GetType().ToString().Equals("OffSiteBackupServiceNamespace.Location"))<br />
{<br />
if(((OffSiteBackupServiceNamespace.Location)item).Checked)<br />
{<br />
saveToLocations.Add((OffSiteBackupServiceNamespace.Location)item);<br />
this.myEventLog.WriteEntry("Active Location read: " + <br />
((OffSiteBackupServiceNamespace.Location)item).ToString());<br />
}<br />
}<br />
thx,
jason
|
|
|
|
|
I'm looking at the tutorial NetworkStuff, and have a question about what is going on in this function:
<br />
private void first_connect(string remote_ip,int remote_port)<br />
{<br />
this.evt_close.Reset();<br />
this.my_connect_remote_ip=remote_ip;<br />
this.my_connect_remote_port=remote_port;<br />
IPEndPoint ipep = new IPEndPoint(System.Net.IPAddress.Any, this.my_local_port);<br />
EndPoint ep = (EndPoint)ipep;<br />
this.datasocket.Bind(ep); <br />
ThreadStart myThreadStart = new ThreadStart(this.my_connect);<br />
Thread myThread =new Thread(myThreadStart);<br />
myThread.Start();<br />
}<br />
Why is this being done before the thread is started for a client connection?
<br />
IPEndPoint ipep = new IPEndPoint(System.Net.IPAddress.Any, this.my_local_port);<br />
EndPoint ep = (EndPoint)ipep;<br />
this.datasocket.Bind(ep); <br />
I thought you did not have to do a bind on a client socket connection?
Thanks for the help.
Tom Wright
tawright915@yahoo.com
-- modified at 16:01 Wednesday 16th November, 2005
|
|
|
|
|
Hi there.
I was wondering about the CheckBox control.
Let´s say one has 10-15 CheckBox controls and wanted to attach a number to each of them (I am not talking about the Text property). For instance cb1 has 250, cb2, has 165, cb3 has 300 and so on. When the checkBoxes are checked could the numbers attached to each checkBox be added together but only the numbers attached to the checkBoxes that are checked?
So if cb2 and cb3 are checked the program would add together 165 and 300.
How would one go about doing this?
Thanks,
FJ
|
|
|
|
|
Hi!
Perhaps the easiest solution would be to assign the value for each CheckBox to the corresponding Tag property.
Then you can simply write:
int sum = 0;
foreach (CheckBox cb in MyCheckBoxCollection)
{
if (cb.Checked)
sum += (int)cb.Tag;
} Regards,
mav
|
|
|
|