Click here to Skip to main content
15,890,670 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
C#
class Program 
{ 
    static void Main(string[] args) 
    { 
        new ShoppingCart().Process(); 
    } 
} 
 
class ShoppingCart 
{ 
    public void Process() 
    { 
        int magicDiscount = 5; 
        // ... 
    }
}




the above code we are calling the method

new ShoppingCart().Process();" explian about this"
Posted

If you make a method static then it is a Class method and can be called on the class, e.g. Int32.TryParse(). All other methods are instance types and can only be called via an object reference.
 
Share this answer
 
The Process method should probably be static. But, as someone else said, you need to buy a book on OO, rather than asking us.
 
Share this answer
 
You are creating an instance of the ShoppingCart class and then calling the Process method on that instance. If you had used the static modifier, you would not have had to create the instance of the ShoppingCart class.
 
Share this answer
 
 
Share this answer
 
just change 'public void Process()' to 'public static void Process()' and you can do 'new ShoppingCart().Process();' kind of method calls. a static method presists in memory and needs only its contaier class name to call it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900