|
It might be worth adding:
if( a == b )
return 0; in case anyone does try to do Compare( a, a ) . It might seem unlikely, but you have to consider aliasing.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Good idea. Might save quite a bit of time since the byte for byte comparison would run max(O(n)) just to return 0.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
|
First of all, this is best suited for a good abstract model. A Person class, for example, would define the common properties and derivative classes (like Executive , Manager , etc.) would define additional properties specific to them (perhaps even extend Person with a Supervisor class, and the latter two classes derive from Supervisor since they would ultimately have something in common).
If you want the PropertyGrid to display properties at runtime that aren't actually defined on the class, implement the ICustomTypeDescriptor on your class. For the most part, just call TypeDescriptor methods for each interface member implementation, passing true for the parameter typically called noCustomTypeDesc . For example:
TypeConverter ICustomTypeDescriptor.GetConverter()
{
return TypeDescriptor.GetConverter(this, true);
} For the two ICustomTypeDescriptor.GetProperties overloads, you return a PropertyDescriptorCollection with the defined properties and shadowed properties.
You can find more information about the ICustomTypeDescriptor in the .NET Framework SDK, but implementing will require understanding the .NET ComponentModel, so I suggest you read Enhancing Design-Time Support[^] in the .NET Framework SDK.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello...
I have a problem...
I want to delete a file but i cant delete it, it thwors an error an sais acces denied!
I have tried this...
string FileFullDest = "C:\test\test.dl";
FileInfo Delete = new FileInfo(FileFullDest);
Delete.Delete();
Don't know what else to do!
Anyone who can help me?
|
|
|
|
|
You can also use File.Delete , but the result is the same if you don't have the necessary file system permissions (for that particular file) or code access security (i.e., permission to delete any file via code in .NET).
Please be more descriptive. What is the exact exception type (ex: SecurityException , etc.) and message text? From where is the application that contains this code run (i.e., local computer, intranet server, etc.)?
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
it trows an IOException!
it sais -> the process cannot access the file "c:\test\test.dll" because it is being used by another process!
But isn't it possible to delete it anyway?
|
|
|
|
|
Not if another process is using it, no. Whatever process has loaded and mapped test.dll into its process space must be shutdown first. Operating systems are supposed to protected against this.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
And there is no way to stop the process at run time?
|
|
|
|
|
Yes, but you have to know what the process is. You also shouldn't just go stopping processes just so you can delete a file.
See the System.Diagnostics.Process class for a way to get a list of running processes. You'd have to enumerate them and then enumerate their Process.Modules property to find which process is using test.dll, then attempt to close it gracefully using Process.Close . If that doesn't work, use Process.Kill to terminate it.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
okay i try that!!
thansk!!
|
|
|
|
|
I sense impending disaster.
|
|
|
|
|
|
That you're trying to make a malicious program.
Jeremy Falcon
|
|
|
|
|
Actually, it was more to do with the fact that he appeared to blindly ignore some of Heath's advice.
Heath Stewart wrote:
You also shouldn't just go stopping processes just so you can delete a file.
After giving this warning, Heath answered the question to which
QzRz wrote:
okay i try that!!
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
My Blog
|
|
|
|
|
I am using the article Inserting XML formatted data into SQL Server 2000 By faisal abdul aziz as a template for some work I doing. I have create a class, in a separate class file, to cover the 'child' elements. I have called this Answers.cs.
The begining of the file looks like this:
using System;
using System.Xml.Serialization;
namespace SGC.Apps.Consultations
{
public class Answers
{
public Answers()
{
}
private int intQNo;
private int intAns;
[XmlAttribute]
public int Question_No {
get {
return this.intQNo;
}
set {
intQNo = value;
}
etc.....
In web form I have button_click event routine
private void Button1_Click(object sender, System.EventArgs e) {
if (Page.IsValid) {
XmlSerializer serlizer = new XmlSerializer(typeof(Replies));
int intCount = 2;
Answers[] ans = new Answers[intCount];
ans[1].Question_No = 3;
etc......
I get the error Object reference not set to an instance of an object
The highlighted line is 'ans[1].Question_No = 3;
Full error is [NullReferenceException: Object reference not set to an instance of an object]
Can anyone help with what stupid thing I am doing wrong?
cheers
Robert T Turner
South Gloucestershire Council
|
|
|
|
|
1: int intCount = 2;
2: Answers[] ans = new Answers[intCount];
3: ans[1].Question_No = 3;
I've numbered the lines above.
In line 2 all you are doing is reserving the space for the objects. You still have to create them. So after line 2 you need to do
ans[0] = new Answer();
Also, remeber that indexes in C# are zero-based. I don't know if you knew that, but it looked odd (line 3) that you were starting on index 1.
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
My Blog
|
|
|
|
|
Colin Angus Mackay wrote:
Also, remeber that indexes in C# are zero-based.
To be complete, indexes in .NET are all zero-based.
[EDIT] Before the ignorant start flaming me for "indexes" check your dictionary. "Indexes" is a perfectly viable alternative to "indices". It's happened before. [/EDIT]
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I might be completely wrong (usually am) but i think you need to set the ans[x] = to an instance of the answer class before you can do anything with it. Because it has not been instantiated yet you get your Null Reference Exception.
Try initializing each element in the array to a blank Answer class.
This sounds right to me but without actually trying it i don;t know.
Let me know how you get on,
Cheers
Kev Pearman MCP
|
|
|
|
|
Thanks to you and all who replied
Robert T Turner
South Gloucestershire Council
|
|
|
|
|
Hi, I have a trivia program wherein i have main form containing a label for player's winnings. the trivia questions are separate forms that is launched when the corresponding button from the main form is clicked. the question forms are timed and once the time has expired, it checks for the correct answer. a price (i.e. $100) is set for each correct answer. the problem im having is that this price is not being updated on the main form label after the time has expired. Can anyone help me please ASAP?
thanks.
Sincerely,
Jason C. Ranin
Software Quality Assurance
|
|
|
|
|
Try calling the TextBox.Invalidate() method, this will force the text box to be re-drawn. If that doesn't work then it may be a problem with how you are passing the value into the text box.
Kev Pearman MCP
|
|
|
|
|
Hi,
I am trying to inventory a directorty with Word documents.
This is on of my first programs in VS, but this is what I've got:
Reference to Interop dll's for Word 2002.
Getting the files from the directory.
Opening the word docs one by one.
But then I'm having trouble getting the Toc of the document.
I want to insert the document per paragraph from the toc in a db.
I have read on MSDN but still no luck.
Does anyone have any tips for me?
Steven T
|
|
|
|
|
Hi,
I have some class in my project like Executive, Manager etc. Each class has some perdefined properties like FirstName, LastName etc. I assign the object of my classes to the property grid, to have these perfined properties in the property grid.
The problem is that i want to add some other properties like Address, Phone, Email etc to my classes (Manager, Executive) at runtime, so that these properties can also be accessed through the property grid. How can i do this.
Thanks in advance,
Omar Rehman
|
|
|
|
|
Please I need to know how to get my speed on the network.
|
|
|
|