locked
No Header Files?? RRS feed

  • Question

  • Hi,

     

                I have a bit of C experience before – and we used to define various global values in a header file that would be included in each of the source files.

     

                I have found C# not to have any header files. Why??

     

                Should I then declare a static class – and use that for storing my settings? Or is there a better way.

     

    Thanks a lot,

    O.O.

               

    Tuesday, December 25, 2007 5:06 AM

Answers

  • Hi,

     

    Yes that is true. C# does not have header files. Instead C# has assemblies containing MSIL code and metadata information. All .NET compliant languages use the metadata to determine the same info as that found in the header files.

     

    Get a C,C++, C# comparison over here

     

    http://www.wilsonmar.com/1cpgm.htm#CVers

     

    http://www.devx.com/MicrosoftISV/Article/11975

     

     

    You can use properties in C# to achieve your requirement

     

    http://msdn2.microsoft.com/en-us/library/x9fsa0sw(VS.80).aspx

     

     

     

    HTH,
    Suprotim Agarwal

    -----
    http://www.dotnetcurry.com
    -----

    Tuesday, December 25, 2007 9:55 AM
  • Hi,

     

    Global Variables:

     

    One of your links clearly says that C# does not have global variables unlike C++ that does. So how do you handle Global variables in C#.

     

    Yes C# does not have global variables. C# has dumped the concepts of global functions, variables, constant. That does not fall into Object Oriented development. As I mentioned in my previous post, you can use static variable in a class to achieve it. (public static ).

     

    This is sort of tied into the concept of Global Variables above. In C and C++ tt was possible to define some constants that were substituted by the pre-processor, before compilation.

     

    Use const.

     

    const int myNum = 20000;

    const string myString= "I love Csharp";

     

     

     

    HTH,
    Suprotim Agarwal

    -----
    http://www.dotnetcurry.com
    -----

     

    Friday, December 28, 2007 6:40 AM

All replies

  • Hi,

     

    Yes that is true. C# does not have header files. Instead C# has assemblies containing MSIL code and metadata information. All .NET compliant languages use the metadata to determine the same info as that found in the header files.

     

    Get a C,C++, C# comparison over here

     

    http://www.wilsonmar.com/1cpgm.htm#CVers

     

    http://www.devx.com/MicrosoftISV/Article/11975

     

     

    You can use properties in C# to achieve your requirement

     

    http://msdn2.microsoft.com/en-us/library/x9fsa0sw(VS.80).aspx

     

     

     

    HTH,
    Suprotim Agarwal

    -----
    http://www.dotnetcurry.com
    -----

    Tuesday, December 25, 2007 9:55 AM
  • Dear Agarwal,

     

                Thank you for your links – but I think I still did not get it.

     

    Global Variables:

     

                One of your links clearly says that C# does not have global variables unlike C++ that does. So how do you handle Global variables in C#.

     

    Constants:

     

    This is sort of tied into the concept of Global Variables above. In C and C++ tt was possible to define some constants that were substituted by the pre-processor, before compilation. E.g.

     

    #define NUM 12

     

                How can this be done in C#.

     

     

    Thanks a lot,

    O.O.

    Friday, December 28, 2007 6:16 AM
  • Hi,

     

    Global Variables:

     

    One of your links clearly says that C# does not have global variables unlike C++ that does. So how do you handle Global variables in C#.

     

    Yes C# does not have global variables. C# has dumped the concepts of global functions, variables, constant. That does not fall into Object Oriented development. As I mentioned in my previous post, you can use static variable in a class to achieve it. (public static ).

     

    This is sort of tied into the concept of Global Variables above. In C and C++ tt was possible to define some constants that were substituted by the pre-processor, before compilation.

     

    Use const.

     

    const int myNum = 20000;

    const string myString= "I love Csharp";

     

     

     

    HTH,
    Suprotim Agarwal

    -----
    http://www.dotnetcurry.com
    -----

     

    Friday, December 28, 2007 6:40 AM
  • Thanks Suprotim Agarwal, for clarifying the issue. I have not used “static” stuff before, but I would attempt to do that in the future.

    O.O.

    Sunday, December 30, 2007 5:02 AM