User Profile
Collapse
-
No, you cannot override the existing == operator (it is a static method). But I wouldn't call that a good idea even if it were possible, modifications like that would be a nightmare to debug. -
That is how things work, the only thing you can do is add a handy extension method to System.Double, something like:
Code:public static bool AlmostEquals (this double a, double b) { return (Math.Abs(a - b) < 1e-5); }
Code:MessageBox.Show((1.0 - 0.8).AlmostEquals(0.2));
Leave a comment:
-
You might want to take a look at Activator.Creat eInstance method.
This should also work:
Code:class OtherClass { public static T CreateInstance<T>() where T : new() { return new T(); } }
In that case you would use it like this:
Code:MyClass obj = OtherClass.Create
Leave a comment:
-
Extension methods are a feature of C# 3.0, but not related to the Framework version.
To use C# 3.0 with .Net 2.0, you will however need Visual Studio 2008, but it will compile and run in CLR 2.0 just like you were using C# 2.0.
By adding a this keyword in the parameter list, you are telling the compiler to add an extension method to the class of the specified "this" type.
For example, to add average,...Leave a comment:
-
But it doesn't display the call stack for the unmanaged side (COM). The problem is that exception happens in the message loop, so the method at breakpoint is Application.Run ():
Code:-- Message: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. -- Stack trace: at System.Windows.Forms.UnsafeNativeMethods .DispatchMessageW(MSG& msg) at
Leave a comment:
-
Additional info:
I cannot find the .def file for the COM dll, so I cannot use it to get the name. I am not interested in instantiating the COM class, I only want to know what function is related to a specified ordinal.
My original problem is that I have found an exception using WinDbg, which happens in ChartFXClientSe rverCore!Ordina l5507(+0x97b7), so I would like to see the specific function to try to isolate the proble...Leave a comment:
-
Getting function names from ordinals in a dll
Hi, first of all sorry if this isn't exactly C++ related, but didn't know where it would be more appropriate.
I am trying to get actual function names from their ordinal numbers from a COM dll. I tried using dumpbin.exe but it only returns [NONAME] for each ordinal (except the first few):
Code:ordinal hint RVA name 21 0 00002439 DllCanUnloadNow 25 1 00007F41 DllGetClassObject
-
Use the dumpbin.exe tool to make sure that you have the correct entry point name in C++.Leave a comment:
-
Check this link for some examples on P/Invoke: http://msdn.microsoft.com/en-us/magazine/cc164193.aspx. There is also a download link for a "PInvoke Interop Assistant" tool, which helps you create the correct DllImport signature (if you did a mistake).
You can get detailed info on string marshalling on this link: http://msdn.microsoft.com/en-us/library/s9ts558h.aspx.Leave a comment:
-
Maybe you could get it from the total number of days between those two dates?
Code:double numberOfDaysElapsed = (date2 - date1).TotalDays;
Leave a comment:
-
-
It exists in VS2005 also: NameValueCollec tion.
But Hashtable also implements IEnumerable for DictionaryEntry objects, so you can also write:
Code:foreach (DictionaryEntry entry in myHashtable) { Console.WriteLine("Key = {0}, Value = {1}", entry.Key, entry.Value); }
Leave a comment:
-
As I said, that example doesn't help you a lot.
Because this code:
Code:public sealed class ReadyForGenericSingleton : AbstractGenericSingleton<ReadyForGenericSingleton> { public static ReadyForGenericSingleton Instance { get { if (!Initialised) { Init(new ReadyForGenericSingleton());
Leave a comment:
-
But the example in the first article looks like this:
Code:public class Singleton<T> where T : class { Singleton() { } class SingletonCreator { static SingletonCreator() { } private static T CreateInstance() { ConstructorInfo constructorInfo = typeof(T).GetConstructor(BindingFlags.Instance |
Leave a comment:
-
To call the GetStorage<T> method, you already need to know the type of T, so it isn't actually a factory.
I still don't understand why Instance needs to be static. If it was public and abstract in your base class (StorageBaseAbs tract<T>), then you could simply get the singleton using:
Code:StorageDataBase db = StorageDataBase.Instance;
Code:StorageDataBase db = StorageBaseAbstract
Leave a comment:
-
The important thing to notice here is that Class1.Instance is of type Class1, while Class2.Instance is of type Class2. Since they are both static and are not defined in any interface or parent abstract class, for C# compiler they are completely different.
You are telling compiler that T should be derived from BaseClass<T>, but you are not telling him that T is Class1 or Class2, so it doesn't want to allow that.
...Leave a comment:
-
Please use CODE tags when posting, it makes your code much easier to read.
How about something like this:
Code:abstract class BaseClass<T> { public abstract T Instance { get; } } class Class1 : BaseClass<Class1> { private Class1() { } readonly Class1 _instance = new Class1(); public override Class1 Instance {
Leave a comment:
-
No, checkboxes will not have an event handler, only the button click event will be handled. Until the button is pressed, you don't need to care about what is going on with the checkboxes.
Just read them all in submitButton_cl ick handler, the same way you created them, using a for loop....Leave a comment:
-
Nevertheless, you need to pass the connection string to SqlConnection to create it. I didn't say that the second part of the code needs to be in the same class as the first part, but you need to have the connection string ready before creating SqlConnection (that's what the error is telling you, after all).
Your class doesn't enforce that in any way - you are creating an SqlConnection from a static string, without knowing if it was...Leave a comment:
-
First problem is that you shouldn't be creating a database connection just like that, "in the middle of nowhere".
Create a private string field which contains the connection string only, and then create a connection only when you need to do a transaction.
Code:// add this to your class, [B][I]but not as a static field[/I][/B] private string connectionString = null; if (open.ShowDialog() == DialogResult.OK)
Leave a comment:
No activity results to display
Show More
Leave a comment: