CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2013
    Posts
    90

    Standard Module in C#

    In VB I used to use modules to declare public variables which are used in entire project.
    In C# which I'm just starting to learn standard modules do not exist and I've read that static variables in the public class may be used.
    In the Window code I have to write Class name where the static variable was declared then dot operator and then the variable itself.
    Is there any way to avoid using the class name everytime I need to refer to the public variable?
    Or there is some other way to store some values avalable in all windows (WPF) or Forms (WinForms)?

    Thank you

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Standard Module in C#

    Quote Originally Posted by chapran View Post
    Is there any way to avoid using the class name everytime I need to refer to the public variable?
    Or there is some other way to store some values avalable in all windows (WPF) or Forms
    No, requiring the class name (or namespace) avoids having to create unique names for the variable.

    Global variables aren't all that great and can lead to issues with regard to finding out where they got changed (in a complex program, it isn't always easy to tell). For this and other reasons, C# decided not to allow them.

    Requiring the class name may seem like a burden, but it really isn't that big of deal.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured