|
Well then, if you take into account that it's almost always optimized into String.Concat , then wouldn't you say that using + is actually much quicker than using String.Format , which involves parsing and appending?
From a readibility stand point, the + operator is superior in my opinion. Now, if special formatting is necessary, then the Format method is available -- for formatting purposes.
Regards,
Alvaro
Give a man a fish, he owes you one fish. Teach a man to fish, you give up your monopoly on fisheries.
|
|
|
|
|
It depends on the circumstances, I'd say. Like you said, for special formatting using String.Format is definitely better, though you could accomplish this task with + or String.Concat if you use the overloaded ToString that corresponds to the IFormattable implementation.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
3) string str = "Date today is " + Date.Now + " !!!!";
ToString() is automatically called for you.
Regards,
Alvaro
Give a man a fish, he owes you one fish. Teach a man to fish, you give up your monopoly on fisheries.
|
|
|
|
|
how do i copy files to the clipboard with csharp so that i can right click a dir and past them into it (i really need to be able to past bitmap into a program but its the same principle)
chad
|
|
|
|
|
Read about the Clipboard class in the .NET Framework SDK. You use it in a similar fashion as you do drag and drop. You fill a DataObject with data and add it to the clipboard, only the DragDropEffects is not used.
To add it:
DataObject do = new DataObject(DataFormats.FileDrop,
@"C:\temp\file.txt");
Clipboard.SetDataObject(do, true); To get it:
DataObject do = Clipboard.GetDataObject();
if (do.GetDataPresent(DataFormats.FileDrop))
{
string filename = (string)do.GetData(DataFormats.FileDrop);
File.Copy(filename, destination);
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
how do i add more than one file to the dataobject
chad
|
|
|
|
|
Use a string[] array of filenames, which you should also check for if you're a drop target for the HDROP format.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
thanks for all your help
chad
|
|
|
|
|
I need to write a voice chat application in C#, but i don't how to write it. Anyone can help me? Mail me in lcsnatoo@gawab.com
Thank
|
|
|
|
|
|
what using system namespace can i find a way to tell if my computer is online? I would like to make a program that keeps checking if my computer is online. WHen i get disconnected from my 56k, i would like this program to close some applications that i will setup up, then once the computer connects (my comp redials automaticaly) the program will notice that the conection is back online and will run the applications. Im learning C# and this is the basic helpful program that i could learn to do.
all i can find are ways to have my program connect online and keep checking using my bandwidth, my very small bandwidth. is there an event that the OS throws when going online or offline that i can check?
modified 16-May-21 21:01pm.
|
|
|
|
|
As a suggestion I would use a thread to continually ping a certain website every .... 1 minute or so ? and when the ping fails you know you are not connected?
|
|
|
|
|
i was thinking that but the problem with my dialup is that when a program is downloading when i try ping from the command window i keep getting "request timed out". Is that ok to use, since there is a website can i take that as a "still online". If there wasnt a website i would get "ping request couldnt find the host..."
also my redial is really quick, it takes about 20 seconds to get back online but i guess i can change that in the connection service properties to wait 1 minute or more before it attempts to redial.
modified 16-May-21 21:01pm.
|
|
|
|
|
http://www.personalmicrocosms.com/html/icc.html
something i found using google
|
|
|
|
|
I've been developing apps in c++ for years using various OS's from Win 3.1 onwards. I've had hundreds of 'application errors' as all developers do.
Recently we have been converting (and adding functionality to) our set of apps with C#. Generally very pleased with advantages of C# over C++. But......
at least 3 times on one development PC and at least twice on another, a c# app has crashed spectacularly - total reset/reboot of WinXP pro, no warning, no error message, nothing. I haven't seen anything like it since the dreaded 'blue screen' of Win95 and 98.
If it's any help, this app's main function is to collect and store (in an SQL database) information arriving via either a network port or a serial port (it has crashed in both cases so I don't think that the external hardware is responsible).
After MS's warning ("this computer has recovered from a serious error") after rebooting, and sending the error report to MS, all they can come up with is a 'unknown device driver error'.
Has anyone else had similar experiences?
|
|
|
|
|
chris fearnley wrote:
Has anyone else had similar experiences?
Nope, in fact the CLR is supposed to protected against this, and it's not like a socket listener application using ADO.NET is anything low-level enough to do something like this (and in fact, it's hard for any managed language to be low-level enough).
If you're P/Invoking code, then it's a different matter. In such a case, make sure you're marshaling parameters correctly and make sure you're not using out and ref keywords (unless the params are pointers to pointers) for reference types, including arrays of value types (since an array is always a reference type). On one occassion I did see someone's code which included this mistake unexpectedly unload the CLR (and hence crash the app) but never a BSOD. The last time I saw a BSOD was on XP with a bad Creative Labs driver (and aren't they all?). To note, I architect .NET solutions all the time and am responsible for many .NET programmers and developers.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Same thing with me. I've doing .net development for few years now, and have never seem any crashes from it. It might be some bad driver on your machine. I've had similar crashes before (non .net development related) with display drivers for gforce video card.
How can you know it's your app crashing the system?
|
|
|
|
|
It's happened on two machines (while running this app) and the machines have been fine at other times. Not much in common with them otherwise except both have XP pro and VS .NET loaded. They're different makes and they're not even in the same building!
Not using any interop services, only the Win32 serial port code as suggested by the JH:Combase class
[DllImport("kernel32.dll", SetLastError=true)]<br />
internal static extern IntPtr CreateFile(String lpFileName........ etc...
which I think I got from CodeProject but can't find now.
Thanks for suggestions so far anyway.
|
|
|
|
|
Hi,
I load a hefty page of controls (loadcontrol), something that requires some time (business logic included). The click event of one of the webcontrols fires after the page_load has loaded all controls again.
Is it possible to handle the click of a webcontrol without having to load the whole set of controls again (if I don't load the control the click event will not fire)? Maybe with SENDER in page_load?
Regards,
Michel
|
|
|
|
|
Dear Sir,
i am not sure but i think that you have to use some scripts to do the job in this web page cuse scripts works in the client side and in this case there are no need to reload all the web page controls
Regards
Mhmoud Rawas
------------
Software Eng.
|
|
|
|
|
That's a part of the problem, we don't want extra client side script since we have webcontrols..
|
|
|
|
|
Try overriding Page.RaisePostBackEvent and provide an implementation of IPostBackEventHandler that uses the information in the post back argument to simulate your control.
There would be a way, though. This isn't like in Windows Forms where the callback (event handler) points to a managed memory address on the heap. Post-back events all original from a simple HTTP POST with a little help from a small piece of client-side Javascript (__doPostBack ).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have a program that runs as a service and needs to know when any user has successfully logged in.
Using the SystemInformation.UserName shows that 'this' process was stated by the 'SYSTEM'.
I have been forewarned about touching the security events by the end users IT management, so looking for a valid logon event with the current setting are out of the question.
Any ideas would be very much appreciated.
Rick
|
|
|
|
|
A service always runs as the user under which it's configured to run. If your service is configured to run as SYSTEM, then it will always run as SYSTEM when the service is started (at startup if configured as such, which is the default behavior). Many services will implement APIs that impersonate users but still can only run as a certain account (like SYSTEM).
If you want to moniter when other users log in (since your service is continually running despites whether or not someone's logged in), then you need to monitor system events. The .NET FCL (Framework Class Library) exposes no such APIs, so you'll have to use unmanaged code through COM interop or P/Invoke.
If you're limited from checking security events, then you could use WMI and handle an event query for the Win32_LogonSession WMI class. The details are buried in Microsoft implementations and all you have to do is register to receive an event when something changes. See the class documentation for the System.Management namespace and see MSDN Magazine[^] for several good articles (including links to more information and a good WMI plugin for VS.NET's Server Explorer (beta for 2002, released for 2003 - but both work good).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello,
My name is Michael Davidov I am 17 years old and a junior in high school. I have been programming in C# since the .NET Framework was publically released. I want to teach a class at my highschool in Seattle about computers and programming and find no easier, or more useful language than C#. My school has never had any form of computer classes or anything remotely related to programming. It actually makes me quite upset considering it is a private school (Seattle Academy of Arts and Sciences)and every student has a nice win2k or XP laptop with a 802.11b connection.
What I really need is a book with lesson plans that other students can consult out of school when I am not available. I have recieved the go ahead to create such a class so I am in need of a text as soon as possible. Also any suggestions on how to GRADE assignments would be very welcome.
Thanks for your time!
Michael Davidov
( MichaelDavidov@seattleacademy.org )
|
|
|
|