Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Public Variable confusion
Message
De
15/01/2013 10:22:16
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01562505
Message ID:
01562593
Vues:
33
Public in .Net is very different than VFP.

First, you have to remember that everything in .Net is an object. When you declare an object public, it doesn't mean it stays around forever and it's values can be seen everywhere. It means its signature can be used anywhere. You still have to instantiate it everytime you want to use it. It's that instantiation that is scoped to where it happens (a method, class, etc). Here's an example (not how I would really code for production. This is simplified for the example)
public class Processor
{
   public string FullName;

   public void BuildFullName(string firstName, string lastName)
   {
      FullName = firstName + " " + lastName;
   }
}

public class TestOne
{
    Processor p = new Processor();
    p.BuildFullName("John", "Smith);
    Console.WriteLine(p.FullName); // prints John Smith
}

public class TestTwo
{
    Processor p = new Processor();
    p.BuildFullName("Fred", "Smith);
    Console.WriteLine(p.FullName); // prints Fred Smith
}
The Processor in TestOne knows nothing about the processor in TestTwo, and vice-versa, even in TestOne and TestTwo are instantiated in the same code.

>That's what I do, too. But I have to admit I don't know why PUBLIC doesn't work. I know PRIVATE memvars will fall out of scope in VFP but thought PUBLICs remained the same, i.e. they stay around until released or the session ends.
Craig Berntson
MCSD, Microsoft .Net MVP, Grape City Community Influencer
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform