|
My mistake. WM_CLOSE messages are not posted to the windows, but WM_QUIT is.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Does anyone know of a detailed rational of the choices and decisions made in implementing generics in C# 2.0?
There are good reasons why Generics are not implemented as C++ templates but in some areas it seems that some aspects of the C++ method could have been implemented and would have been superior.
The difference that most concerns me is that with C++, template methods are (normaly) only instantiated if they are referenced and this allows templates to support extra functionality if the parametric class supports it.
For example: I want to create a general struct Pair<T1,T2> . I must immediately decide whether or not it is IComparable and this depends on whether or not its type parameters are constrained to be IComparable .
I no see reason (other than devising a syntax) why implementation of the interface should not be conditional on a where clause restriction on the parametric types.
The parametric restriction of methods is even simpler in principle since a syntax already exists for generic methods that would just need to be extended to allow reference to the parametric types of the class - If the class parameters did not satisy the where clause then the method would not exist and couldn't be called.
A very simple example of my idea:
class Pair<T> : (IComparable where T: IComparable)
{
T first;
T second;
public int CompareTo(object other) where T: IComparable
{
int r1 = first.CompareTo(other.first);
return r1 != 0
? r1
: second.CompareTo(other.second);
}
}
Obviously the compiler would have to verify that the constraints on the interface gaurantee the constraints on the methods needed to implement it.
|
|
|
|
|
Firstly, how is your example different from the implemented generics in 2.0? I can write the same class as
class Pair<T> : IComparable where T: IComparable
{
T first;
T second;
public int CompareTo(T other)
{
...
}
}
Maybe I'm failing to see your point.
As far as why .NET generics are different from C++ templates, it's because with C++, all template instantiations are known at compile time! With a .NET assembly, your dll or exe could be loaded by someone else and could try to make invalid instantiations of your generic class after compile time.
Take for instance the following class:
class MyGenericDotNetClass<T>
{
void FooBar(T foo)
{
foo.Yippie();
}
}
This would work as a C++ template, provided that any code that instanciates this class will provide a generic parameter type that has a .Bar() method. With a C++ template, if you said new MyGenericDotNetClass<sometypewithyippiemethod>(), then this would work because the C++ compiler would verify that the .Yippie() method exists for type SomeTypeWithYippieMethod.
.NET, on the other hand, can't depend solely on compile-time checking. Sure, the compiler could check to see if all your code that instantiates this class does so with a type that has a .Yippie() method. However, .NET code is easily shareable between components; a Visual Basic.NET application my load up your MyGenericDotNetClass and with a generic parameter of SomeTypeWithNoYippieMethod(). Of course, the VB.NET compiler could issue an error message, however, we'd then start getting into long, cryptic error message akin to C++ template compiler erros about bad instantiations because no .Yippie() method exists on the proposed generic type. Obviously, this is a quite simple example, real-world code would get much hairier than this. So the .NET designers decided that if you want functionality out of your generic class, you have to specify it explicitly in the form of a constraint.
Ian Griffiths has a good article on his blog here[^] about this very topic.
IMO, generics in .NET is pretty well done. I like it, it's useful, and saves a lot of development time. I think the only change I'd make is for the value types to have an arithmetic constraint of some sort, allowing generic types to easily add, subtract, multiple, divide, etc. But I hear there are plans for this in .NET version 3.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Conversation With a Muslim
Judah Himango
|
|
|
|
|
You miss the point - Your Pair<T> can only be instantiated with a class implementing IComparable even if, for some particular use, the IComparable part of the functionality is not required.
My class can be seen as two classes with the same name - one of which implements IComparable and one of which does not. All that is required is for the compiler to pick the right one based on the constraints. No CLR/JIT changes would be required because it would all be handled by the compiler.
You might say that you should just have two generics Pair<T> and ComparablePair<T> but, apart from the fact that this is ugly, consider generic collections: either they are restricted to IComparables or they cannot be comparable themselves so then you need Col<T> and ComparableCol<T> for every collection type and, in general, the deeper you nest generics and the more interfaces you consider the more you find that you must either give up your functionality or seriously constrain the parameters that you use.
[Obviously you can always implement IComparable and use runtime casting and throw exceptions if T isn't itself IComparable but that is inefficient, ugly and a serious cause of errors]
|
|
|
|
|
Nick Hounsome wrote:
You miss the point
I figured I did. I'm understanding it now.
Yeah, it's an interesting idea. Gives you more flexability in the types you can instantiate the generic type with, but also puts a burden on developers as far as the "implements IFoo where T implements IFoo" part, but interesting nonetheless. Maybe you could offer this as a suggestion at MSDN labs.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Conversation With a Muslim
Judah Himango
|
|
|
|
|
Hi,
I want to serialize and deserialize objects that has fields with åäö in the names.
serializing them works fine, but deserializing doesnt work and the formatter complains about invalid chars in the tag names.
is there any workaround for this?
|
|
|
|
|
I am a C programmer attempting to learn C# and the problem I have is that I need to call/execute an external program from within a C# program I have written.
Please tell me how to do this.
Regards,
Alf Stockton
|
|
|
|
|
Try this
using System.Diagnostics;<br />
.<br />
.<br />
.<br />
.<br />
Process.Start(@"C:\Softwares\Ws_Ftp\WS_FTP95.exe");
<font=arial>Weiye Chen
Life is hard, yet we are made of flesh...
|
|
|
|
|
Gee that is easy enough. Thank you.
|
|
|
|
|
You are welcomed.
<font=arial>Weiye Chen
Life is hard, yet we are made of flesh...
|
|
|
|
|
Process.Start appears to only be able to start a process on the same machine.
Is there a way to start a process or preferably a php program on a remote machine.
What I want is to call a php on the server from a C# program on a workstation.
Regards,
Alf Stockton
|
|
|
|
|
I am writing a server application using SOAP over TCP (soap.tcp) in C#. I want to
generate a WSDL file from this uri "soap.tcp://localhost:8080/stockservice".
All I have heard is that its not possible to add a web referene as it
happens to generate proxy class for a http request .'If the SoapService
endpoint is bound to an HTTP endpoint, you can request the WSDL definition
by appending '?wsdl' to the endpoint address.However since the release of
WSE 2.0 and WS-Addressing many leading service providers are using TCP.The
"?wsdl" approach doesn't make sense for protocols such as TCP that don't
support the notion of a query string. MS has provided a generic way to get
WSDL Simply send a SOAP message with an action of
http://schemas.microsoft.com/wse/2003/06/RequestDescription
and an empty body, as illustrated here:'
--------------------------
soap:Envelope xmlns:wsa="..." xmlns:soap="..." ...>
<soap:header>
<wsa:action>http://schemas.microsoft.com/wse/2003/06/
RequestDescription
...
<soap:body>
-----------------------------
Now I have created a method given below that returns the above mentioned
soap envlope, and further i m sending it from client program using
"sender.Subscribe(env)".
private static SoapEnvelope CreateSubscriptionMessage()
{
SoapEnvelope env = new SoapEnvelope();
XmlElement header = env.CreateHeader();
env.Envelope.AppendChild(header);
header.AppendChild(env.CreateElement("wsa:Action"));
header.FirstChild.InnerText=
"http://schemas.microsoft.com/wse/2003/06/RequestDescription";
Console.WriteLine(env.Envelope.InnerXml);
return env;
}
-------------------
I dont know how it will gonna return WSDL in response to this soap packet.
And how to recieve that WSDL ..
Could some body please provide or direct me to some sample by using which I
could receive WSDL and save it in a file.
thanks in advance
iffi
|
|
|
|
|
hi all,
I want to change default wait Image of the Cursor.Nomally we are doing it like this.
this.Cursor=System.Windows.Forms.Cursors.WaitCursor;
Now it appears it default Image.can we change that Image and put there my own ,custom Image?
thanks in advance.
|
|
|
|
|
I have an access DB and want to be able to change the allowzerolength property for a column. How can I do this using C# code?
Thanks
Paul
|
|
|
|
|
Hello,
I have to call one function in C++ DLL from c#.Net project.How can i do that?
Amruta
|
|
|
|
|
[DllImport("yourLib.dll")]
private static extern void yourFunction();
_________________________________
Please inform me about my English mistakes, I still try to learn your language!
|
|
|
|
|
I tried using that DllImport but the problem is in difference of data types while calling the function in c++ from C#.
Amruta
|
|
|
|
|
hi i m new on c#.net i have to develop a Form for Data Input and i need to use a DataGrid on it (with ComboBox and DTP on it), can anyone send me the example of such scenario.
i'll b very much thankful for this act.
A H Khan
dcet99@hotmail.com
|
|
|
|
|
for getting data out of the database use Connection/DataAdapter/Datasets classes (odbc, oledb or SQl)
binding data to the datagrid use datasource (this also works for Arrays and ArrayLists)
To insert combos or any other gui-objects into the datagrid search on Templatecolumns, there are some tutorials here on CP.
I didn't play in winforms with datagrids much, but in ASP.NET I usually called a function which created my datagrid programmatically.
good luck.
No hurries, no worries.
|
|
|
|
|
Is it possible to create programmatically ne database file (SomeDatabase.mdb)?
|
|
|
|
|
I want to write DCOM components,but I don't know how to write the DCOM components in C#.
P:-Dlease tell me about it!
if possibility,please give me some examples about it!
Thank you!
|
|
|
|
|
First hit[^] on a google search.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Another idiot who doesn't like it when you tell them "Google is your friend!". I hate it when people come here and expect you to hand feed them every detail they want to know! Whatever happened to programmers doing their own research?! How on earth do these people learn anything?!
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Dave Kreskowiak wrote:
Whatever happened to programmers doing their own research?! How on earth do these people learn anything?!
Yeah, it's a worry. I used to just say 'google', now I actually give the link as well as telling them how I got it. Still, people are not happy.
But at the end of the day, it's all good news for you and me. None of the 'I can't do my own research' brigade are ever going to put us out of a job.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Christian Graus wrote:
None of the 'I can't do my own research' brigade are ever going to put us out of a job.
Soooo true! There is a bright side!
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|