3 Replies - 1231 Views - Last Post: 16 January 2008 - 07:17 AM Rate Topic: -----

#1 pietra  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 70
  • Joined: 08-February 07

Use of static

Posted 14 January 2008 - 04:16 AM

Hello to all.

I'm not sure I used correct forum, if I haven't I appologize.

Questions are:
why to use static members/methods? And when exactly?
what's the difference between static and instance members/methods?

I know this is beginners question, but please be patient I'm trying to learn and understand :)

Thank you

Is This A Good Question/Topic? 0
  • +

Replies To: Use of static

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Use of static

Posted 14 January 2008 - 12:13 PM

Static keyword in C#.
MSDN Static
Was This Post Helpful? 0
  • +
  • -

#3 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1632
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Use of static

Posted 14 January 2008 - 09:03 PM

When you declare a method or property as static, there is no need to instantiate the object to access the metod or property, herer's an example:

Static


namespace PC
{
		public class RandomClass
		{
			  static string _name;

			  public static SomeProperty
			  {
					 get { return _name; }
					 set { _name = value; }
			   }
		 }
}


//Now to access the property in a different form (Web or Windows)

RandomClass._name = "PsychoCoder";




Non Static


namespace PC
{
		public class RandomClass
		{
			  string _name;

			  public SomeProperty
			  {
					 get { return _name; }
					 set { _name = value; }
			   }
		 }
}


//Now to access the property in a different form (Web or Windows)

RandomClass rc = New RandomClass():
rc._name = "PsychoCoder";




Hope that helped? :)
Was This Post Helpful? 0
  • +
  • -

#4 pietra  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 70
  • Joined: 08-February 07

Re: Use of static

Posted 16 January 2008 - 07:17 AM

View PostPsychoCoder, on 14 Jan, 2008 - 09:03 PM, said:

Hope that helped? :)

It helped a lot! Thank you :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1