Advertisement
Guest User

Untitled

a guest
Mar 8th, 2013
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.73 KB | None | 0 0
  1. //Program.cs
  2. public class Program {
  3.     public static User user = null;
  4.     public static void main() {
  5.         //stuff
  6.     }
  7. }
  8.  
  9. //User.cs
  10. public class User {
  11.     //whatever you have in here
  12.     public String aMethodInUser() {
  13.         //stuff
  14.     }
  15.     public static int totalUsers() {
  16.         //return total users (static method)
  17.     }
  18. }
  19.  
  20. //ANY other file can now access user
  21. public class MyOtherClass {
  22.     public int doSomethingCool() {
  23.         //you can then access your user object like this;
  24.         System.out.println(Program.user.name);
  25.         doSomethingElse(Program.user);
  26.         Program.user.aMethodInUser();
  27.         //and if User has any static methods, you don't need a reference
  28.         //to any particular instance, and can do things like;
  29.         System.out.println(User.totalUsers());
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement