Page 1 of 3 123 LastLast
Results 1 to 10 of 28
  1. #1
    Join Date
    Nov 2006
    Location
    Texas
    Posts
    521

    two questions about C#

    Im converting some C++ code to c# and I need two things. I need vector equvilant container and I need to know to 'pass by reference' since '&' dosent work. Also is there already 2D dynamic array available or is that something Ill have to write myself? Thanks.

  2. #2
    Join Date
    Oct 2006
    Posts
    1,548
    Pick up a book on C# ?

    http://msdn.microsoft.com/en-US/libr...=VS.80%29.aspx

    Spoon feeding you this kinda of info isnt going to help. You need to learn what references are in C#
    Last edited by wforl; 12-01-2010 at 10:43 AM.
    [quote][\quote]

  3. #3
    Join Date
    Sep 2008
    Location
    Salisbury, UK
    Posts
    2,812
    I believe there may be C# tuition available on 3dbuzz, possibly...

    Come on now, doddy

    Seriously; the Hyperion project from XNA 101 is free-to-all, and, given that you know C++, you're bound to be able to infer what you need just from that, I'd imagine.

    Cheers, G.

    I found
    my current avatar on google, so props to THIS GUY who created the original...

  4. #4
    Join Date
    Nov 2008
    Location
    41° 28′ 56″ N, 81° 40′ 11″ W
    Posts
    2,399
    Well, sure, the syntax is almost identical between the two languages, if you know how to define classes, objects, and know how to do code blocking, C# should almost be second nature to you.
    PC Specs: Antec 900 ATX Case, Gigabyte 790GX Mobo, AMD Phenom II x4 955, Corsair HX620W PSU, Corsair Vengeance 16GB (4x4GB) DDR3-1600, EVGA GTX 680 2GB GDDR5, 3D Vision Kit 2, LG 8x Blu-ray Burner, Intel X25-M SSD, 500GB+640GB WD Caviar Blacks, Win 7 Pro x64, DAS Pro K/B, MX518 Mouse, Logitech Z-2300 Speakers, Toshiba 32TL515U 32" 3DTV, Wacom Bamboo Fun Large Tablet.

  5. #5
    Join Date
    Feb 2005
    Location
    Bellevue, WA
    Posts
    3,251
    But his question is about a concept that is completely different between the languages. Similar syntax does not mean that the concepts are the same.

    For example, in C#, EVERY object is passed by reference. In C++, they are copied, unless passed by pointer or by reference.

    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." ~Rich Cook

  6. #6
    Join Date
    Mar 2004
    Posts
    0
    Quote Originally Posted by owensd View Post
    But his question is about a concept that is completely different between the languages. Similar syntax does not mean that the concepts are the same.

    For example, in C#, EVERY object is passed by reference. In C++, they are copied, unless passed by pointer or by reference.
    Exactly. I was going to post a similar thing, because initially similar syntax will allow you to get into the language. However, you end up writing C# code a lot differently then C++ code, mainly due to C#'s functional aspects (implicit typing, lambdas, deferred execution, ect - though C++0x does include lambda support), C# being garbage collected (instead of worrying about _how_ you manage garbage collection, you must now understand the rules in which a resource will be collected) and the fact that due to the CLR's understanding of what would be compiler-time constructs in C++ (generics, types, ect).

  7. #7
    Join Date
    Oct 2006
    Posts
    1,548
    For example, in C#, EVERY object is passed by reference
    Thats not true
    [quote][\quote]

  8. #8
    Join Date
    Mar 2004
    Posts
    0
    Quote Originally Posted by wforl View Post
    Thats not true
    /me boxes wforl

  9. #9
    Join Date
    Nov 2008
    Location
    41° 28′ 56″ N, 81° 40′ 11″ W
    Posts
    2,399
    Well, I guess the simplest way to prove the difference would be an object-oriented "Hello, World" app, since OOP between C++ and C# can be a bit different, here's a couple of examples:

    If you are already familiar with C++, you already know that to make a Hello World app in OOP, you would do this, right?

    Code:
    // This is an example of an object-oriented program featuring "Hello, World" in C++
    
    #include <iostream>  // Required for cin and cout as well as for user interaction
    #include <stdlib.h>  // Required to clear the screen in this program
    
    using namespace std;  // Hold a namespace that adds std:: to every line so it's not necessary to type this every line
    
    // Declare function for HelloWorld()
    
    void HelloWorld();
    
    // Start main function
    
    void main()
    {
    	int quit;
    
    	system("CLS");  // Clear the screen
    	HelloWorld();
    
    	// Jump back to this after displaying the message
    	cout << "Press <0> + <ENTER> to return to Windows:  ";
    	cin >> quit;
    }
    
    
    // Move to this function to print out Hello World.
    void HelloWorld()
    {
    	cout << "Hello, World!" << endl;
    	cout << "How's it going?" << endl;
    }
    Now, here is that same exact program in C#, notice the difference in the format of this language:

    Code:
    using System;
    
    
    namespace HelloWorldCS
    {
    
        class HelloWorld
        {
            public static void Hello()
            {
                Console.WriteLine("Hello, World!");
                Console.WriteLine("How's it going?");  
                GoodBye.Bye();
            }
        }
    
        class Program
        {
            static void Main(string[] args)
            {
                Console.Clear();
                HelloWorld.Hello();
            }
        }
    
        class GoodBye
        {
            public static void Bye()
            {
                Console.WriteLine("Press <ENTER> to Quit to Windows:  ");
                var consoleKeyInfo = Console.ReadLine();
            }
    
        }
    }
    See the difference between the two Hello, World apps? So you can see where the difference lies in all this. Just thought I'd give you a heads up.
    PC Specs: Antec 900 ATX Case, Gigabyte 790GX Mobo, AMD Phenom II x4 955, Corsair HX620W PSU, Corsair Vengeance 16GB (4x4GB) DDR3-1600, EVGA GTX 680 2GB GDDR5, 3D Vision Kit 2, LG 8x Blu-ray Burner, Intel X25-M SSD, 500GB+640GB WD Caviar Blacks, Win 7 Pro x64, DAS Pro K/B, MX518 Mouse, Logitech Z-2300 Speakers, Toshiba 32TL515U 32" 3DTV, Wacom Bamboo Fun Large Tablet.

  10. #10
    Join Date
    Aug 2005
    Location
    mantragora
    Posts
    763
    Hm... Wedgie, to be fair i don't see any OOP programming in your example. What you showed here is on the basic C level not C++.
    Since C++ is called "C with Classes" you should atleast use some classes here if you wan't compare those two languages.

    My two cents .

    Code:
    #include "stdafx.h"
    #include <iostream>
    
    using namespace std;
    
    namespace HelloWorldCPluSPlus
    {
          class GoodBye
          {
          public:
                static void Bye()
                {
                      cout << "Bye" << endl;
                      system("pause");
                }
          };
    
          class HelloWorld
          {
          public:
                static void Hello()
                {
                      cout << "Hello, World!" << endl;
                      cout << "How's it going ?" << endl;
                      GoodBye::Bye();
                }
          };
    }
    
    int main()
    {
          system("CLS");
          HelloWorldCPluSPlus::HelloWorld::Hello();
    
          return 0;
    }
    Now difference doesn't look so big.
    Last edited by swann; 12-03-2010 at 05:01 PM.

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •