No, its not possible to separate the declaration from the implementation. There is no need for that to happen as you don't need to #include headers anywhere. IMO that is one of the better features of C# over C++.
Out of curiosity why do you want to do this anyway?
You should start with the C# Language Specifications at http://msdn.microsoft.com/library/en-us/cscon/html/vcoriCStartPage.asp[^]. Also understand that C# is just another language that targets the Common Language Runtime (CLR), the runtime part of the .NET Framework. All .NET compilers compile to similar IL. The only differences in the generated IL usually have to do with compiler optimizations, but some languages support features of the .NET Framework that others don't. For example, C# supports unsafe contexts (in order to use pointers for, say, quick string parsing) while VB.NET does not (yet). But this is not really a feature of C# per se, but a feature of the .NET Framework that C# supports.
Also understand that assemblies written in any source languages can be used by any other managed language.
Finally, there is also Managed C++ that can compile down to IL in an assembly. The major thing to realize here is that you can use mixed mode or pure managed code. Mixed mode includes native implementations that aren't managed by the CLR while pure managed code is.
It's call "managed" because the CLR managed the memory (though classes that encapsulate native resources like Windows should implement IDisposable and clean-up the native resources since they aren't managed by the CLR).
I know that there is MC++ that can access to CLR, but I wanna learn C#. C# seems to be more convinent to access .NET features. I have to write an application that targets Excel 2003 in C#. I don't want to program Excel 2003 with C++, it would be too complex, while Excel 2003 is designed to be easily accessed via C# or VB .NET...
While learning C# which I discover since last monday, I need to get the equivalents between C++ and C# to go faster in my learning, for this, I translate some simple MFC applications in C#...
C# in itself is easy (it's very similar to C++), but it's the .NET framework that is not easy for a beginner in .NET. I have the same feelings with .NET that I had with MFC 10 years ago: " wow!"
I only mentioned that about MC++ to help you better understand the .NET Framework. I read that you wanted to learn C#.
You should also scan through the .NET Base Class Library reference in your help files (or on MSDN Online). Knowing what's there is good so that you can think of better solutions using what's provided. Also look through them any articles here on CodeProject for examples of programming with C#. There's also several examples in the .NET Framework SDK.
Colin Angus Mackay wrote: No, its not possible to separate the declaration from the implementation. There is no need for that to happen as you don't need to #include headers anywhere. IMO that is one of the better features of C# over C++.
This is not inherently correct. While it maybe in the context of C++ (i.e.; no header files in C#), you can have a separate file that is part of the same namespace which simply defines interfaces. These interfaces can then be implemented throughout your application as a whole. This could be seen as a separation of declaration and implementation.
Nick Parker wrote: This is not inherently correct. While it maybe in the context of C++ (i.e.; no header files in C#), you can have a separate file that is part of the same namespace which simply defines interfaces. These interfaces can then be implemented throughout your application as a whole. This could be seen as a separation of declaration and implementation.
Has anybody attempted the following? If not, once I've done it, I'll submit the article!
I want to set up a class that holds a collection of arrays and lets you set up calculations on the arrays that are then run as a block. The calling code would then look something like:
This will be executed as-is by the CLR because the expressions are compiled to IL as you see them. Instead, you should consider storing an expression string as you could with a ColumnHeader (for a DataGrid). You would have to devise somewhere to parse this expression, thoug, perhaps using a string tokenizer like we've done in our app I architected at work. There is an article that includes source that was the basis for our string tokenizer: http://www.c-sharpcorner.com/Code/2003/June/JavaLikeStringTokenizer.asp[^]. This may help.
Thanks for this - I'll have a look at the article. I broadly had in mind that by overloading the operators, I could have them 'stack up' the commands in a buffer (I had Forth and Reverse Polish Notation in mind). The execute method would then run through the buffer, Emit it (perhaps), and then execute it repeatedly.
- what is the equivalent of WM_NCHITTEST message in C#? I want to detect the movments of a window (Form) when the user moves it with the mouse. I tried the MouseUp and MouseDown events, but it works only in the client area of the form (like for C++)
- how to include a manifest resource in C# to apply the current theme in each forms of the application?
Second question: see my article at http://www.codeproject.com/csharp/dotnetvisualstyles.asp[^]. This works for application targeting the .NET 1.0 Framework on up, though .NET 1.1 added an Application.EnableVisualStyles method that you can call before executing Application.Run in your application's entry point. Note that many people have experienced odd problems with the latter method, though, while the method described in my article works because it's exactly what win32 applications do (also note that the .manifest file can stand alone from app as I mentioned, but then you have to worry about deploying that, too).
How do you do that? Let's say you have the following code:
InternetExplorer ie = new InternetExplorer();<br />
IHTMLDocument2 doc = (IHTMLDocument2) ie.Document; //is this correct? should there be a new operator?<br />
//NOTE: How do I know when or not the method returns a "new" object vs. using the new keyword? eg. WebRequest wr = WebRequest.Create("...") not = new WebRequest (but I only know that because it's in the documentation) ??
Back to InternetExplorer: the problem arises when I try to access any of it's interfaces. Example:
ec.item(I don't even know how to use the params properly) or ec.tags("BODY") for example all give me one error: Referenced object does not exist in memory, or something of that sort that means you can't access it.
Help! Good book? Good article?
"A good friend, is like a good book: the inside is better than the cover..."
As you can see above, too, I use Navigate2. This is recommended by the IE Programming documentation.
As far as casting vs. new, you want to use casting. When you cast to an interface that is delcared as a RCW interface, this results in a QueryInterface of the object as you would do in C++ regarding COM. If null is returned, the object does not implement the interface.
Also, use the WebBrowser control by interop'ing shdocvw.dll to embed "Internet Explorer" in your application. Use the InternetExplorer object if you want to control a remote application instance through out-of-process automation.
It's just how you escape Unicode characters in a string. To see what the Unicode characters are, you can use the Character Map in the Start->Programs->Accessories->System Tools program group, or go to http://www.unicode.com[^].