Sajjadkhan
Full Member level 5
- Joined
- Sep 25, 2010
- Messages
- 307
- Helped
- 17
- Reputation
- 34
- Reaction score
- 16
- Trophy points
- 1,298
- Location
- Rawalpindi,Pakistan
- Activity points
- 4,199
Hi guys, i have stated learing C# and i am confused about these terms.
Now i know whats happening here as i commented in last lines of code. same example i encountered in previous but with integer, over looked and didn't bother searching for its use. but i think this will bug me ahead.
so kindly tell me whats the advantages of static and nonstatic? any realtime example would be helpful,thanks.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Functions_basics_1
{
class Example
{
public int abc;
public static int xyz;
public void memberfunction()
{
Console.WriteLine("this is a member function");
}
public static void classfunction()
{
Console.WriteLine("this is a class function");
}
static void Main(string[] args)
{
Example example = new Example();
example.memberfunction();
Example.classfunction();
example.classfunction(); // cant access class function via an object
Example.memberfunction(); // cant access member function via class
Console.Read();
}
}
}
Now i know whats happening here as i commented in last lines of code. same example i encountered in previous but with integer, over looked and didn't bother searching for its use. but i think this will bug me ahead.
so kindly tell me whats the advantages of static and nonstatic? any realtime example would be helpful,thanks.