Thread: Some basic Q's about C#

  1. #1
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657

    Some basic Q's about C#

    #I could not find satisfactory answers for my questions elsewhere..
    1. Can I use C# to build Gui's for Linux programs without using external libraries ?
    2. Can a single program combine C/C++ and C# code nicely ?
    3. Is the code more portable than C++?
    4. Is low level jobs possible at all...?..(I read that there are no pointers....but can we use..for example inline assembly..)

  2. #2
    Registered User
    Join Date
    Mar 2011
    Posts
    41
    1) .NET is an external library (as is Mono) but it's designed to be used with C#. You shouldn't need anything else.
    2) You can use C/C++ DLLs in C#
    3) With C# you can program Windows PCs, Linux boxes, Windows 7 phones, XBox 360 and Android phones. Of these, C++ is only usable on Windows PCs and Linux.
    4) There are pointers, but some stuff you still can't (or shouldn't) do due to the limitations of the .NET runtime.

  3. #3
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    I thought that .NET and Mono were very identical..
    How much do they differ?

  4. #4
    Registered User
    Join Date
    Mar 2011
    Posts
    41
    FAQ: General - Mono will tell you more about the differences. I don't do Linux, so I don't have first-hand knowledge.

  5. #5
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    With Monotouch you can also target the iPhone/iPad/iPod Touch. And of course Mono also runs on Mac OS X.

  6. #6
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    A final Question...
    Would C# be a better platform....as compared to C/C++ and python?..If the only sort of programming I'd do is writing open source GUI programs for a Linux environment ..

  7. #7
    Registered User
    Join Date
    Mar 2011
    Posts
    41
    Some people won't use Mono as they believe Microsoft is going to come eat their children or something. If you want a wider audience then I wouldn't use Mono. If you just want to code, C# is fine.

  8. #8
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by Momerath View Post
    Microsoft is going to come eat their children or something..
    That was classic..!
    I don't think a sufficiently good software would be hindered because of negative publicity of its runtime library..
    Apart from that ..is there serious performance issues?

  9. #9
    Registered User
    Join Date
    Mar 2011
    Posts
    41
    I don't use Linux, so I can't speak from experience there. But on Windows, there isn't. And the ease of .NET (or Mono) GUI programming vs C++ GUI is vast. You'll be done with the .NET version before you figure out how to create a window in C++

    Let the language wars commence!

  10. #10
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Then I think ..my best choice would be to make the libraries and classes in C++ and only the GUI in C# !

  11. #11
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by Momerath View Post
    2) You can use C/C++ DLLs in C#
    but only on windows.

    3) With C# you can program Windows PCs, Linux boxes, Windows 7 phones, XBox 360 and Android phones. Of these, C++ is only usable on Windows PCs and Linux.
    this statement is absolutely false. C++ can be used on literally ANY system. there are ports of the GCC compiler that target nearly every architecture, including xbox and android.

    4) There are pointers, but some stuff you still can't (or shouldn't) do due to the limitations of the .NET runtime.
    the biggest drawback I see in .Net/Mono is that the compiling of code at run time reduces the opportunity to optimize the generated code.

  12. #12
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    3. Is the code more portable than C++?
    It is advertised as such. Theoretically, yes, it is. The idea is that every system has a Virtual Machine, the .NET Runtime Libraries so you can run C#. Then if you want to upgrade your system, you still can run the same C# code without re-compiling. If you are targeting embedded systems and stuff like that where everyone is likely to have different OS then C# could be excellent. IF they support the .NET Runtime Libraries so you can run the code through a VM etc etc.
    Practically, that won't be the case. Where native code is always supported.
    Then think that Java offers the same thing as C#. Even if I considered it a weaker language, there are systems where the VM is implemented for Java and they don't want to invest on doing the same thing for C#.
    Note also that Microsoft doesn't offer its own support for Linux. It doesn't have the policy on making C# work everywhere in general.

    4. Is low level jobs possible at all...?..(I read that there are no pointers....but can we use..for example inline assembly..)
    There are actually pointers in C#, you just have to label the function "unsafe". I am sure they have limitation of course. You can use assembly lines in C code and make a DLL. I am not aware of a DLL limitation so maybe this is not possible.

  13. #13
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Code:
    It is advertised as such. Theoretically, yes, it is. The idea is that every system has a Virtual Machine, the .NET Runtime Libraries so you can run C#.
    Then..would I be able to do things like..say..design a windows forms application in Visual Studio....and use it for a Linux application under mono runtime... i.e...is the .NET runtime free of the Windows API....and does it have ways to create ui's without Windows API ?

  14. #14
    Registered User
    Join Date
    Mar 2011
    Posts
    41
    According to this they do support Forms.

  15. #15
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    But that is exactly the point. The .NET Runtime can use the Windows API if it is installed for Windows and use the "Linux API" if it is installed under Linux.

    The difference with pure C++ is that you would have to re-compile it. Which not all users can do that. That is why you have a different version for different system.s
    Of course Linux don't use .exe files so OK. You see the limitations. Don't know how you can run your Windows Forms application. This would have been a good example for Java and .jar files. Except if there is a similar mechanic for C#...

    So you have to differentiate if the program is portable and if the code if portable. You can use a library, like QT, for GUIs that are portable in Windows, Linux and Mac OS. But you need to compile it for all those systems. And for 32bit and 64bit versions of those.

    To understand the above think of this
    Code:
    //FormLinux.cpp
    class Form
    {
      ...
    }
    Code:
    //FormWindows.cpp
    class Form
    {
      ...
    }
    Code:
    //Your code
    int main()
    {
       Form myForm();
    }
    So if you use the above in QT, as an example, where Form is supposed to be something like a Windows Form, your code is portable. If you compile it in Linux it will use FormLinux.cpp if you compile it under windows FormWindows.cpp. But your code won't change at all.

    Something similar, but without compiling, can be down with a VM. You just tell it "built a Windows Form", the what API to use and how exactly to do it you don't care.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. very basic c
    By jayparrillo in forum C Programming
    Replies: 26
    Last Post: 01-19-2011, 12:40 PM
  2. Need help with some basic C++
    By 3321thec in forum C++ Programming
    Replies: 6
    Last Post: 09-06-2007, 08:15 PM
  3. need some help with basic C++
    By ramonnie in forum C++ Programming
    Replies: 6
    Last Post: 06-28-2007, 11:15 AM
  4. basic
    By srinu in forum C Programming
    Replies: 3
    Last Post: 02-13-2003, 08:21 AM
  5. This is basic C++
    By incognito in forum C++ Programming
    Replies: 10
    Last Post: 12-12-2001, 08:51 AM