C#, why static?
From: Markus (markussteen_at_chello.se)
Date: 08/30/04
- Next message: Ulrich Eckhardt: "Re: C#, why static?"
- Previous message: Xiangliang Meng: "Who can provide me some help on how to eliminate delay and speed up the setup process."
- Next in thread: Ulrich Eckhardt: "Re: C#, why static?"
- Reply: Ulrich Eckhardt: "Re: C#, why static?"
- Reply: Will Twentyman: "Re: C#, why static?"
- Reply: Ashish Poddar: "Re: C#, why static?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 30 Aug 2004 06:14:31 -0700
Hi, I'm trying to learn some C#. Can somebody help me with explaining
why the values Frank and Sinatra has to be declered static, (check
code below)? If they aren't, It wont compile correctly:
(24,41): error CS0120: An object reference is required for the
nonstatic field, method, or property 'MyOwn.MyClass.value'
(24,62): error CS0120: An object reference is required for the
nonstatic field, method, or property
'MyOwn.AnotherOwn.AnotherClass.value'
Thanks for taking your time helping me with this!
Markus
using System;
using System.Threading;
namespace MyOwn
{
public class MyClass
{
public static string value = "Frank";
}
namespace AnotherOwn
{
public class AnotherClass
{
public static string value = "Sinatra";
}
}
}
class MyApp
{
public static void Main()
{
Console.WriteLine("My name is {0}",
MyOwn.MyClass.value
,MyOwn.AnotherOwn.AnotherClass.value);
Thread.Sleep(100000);
}
}
- Next message: Ulrich Eckhardt: "Re: C#, why static?"
- Previous message: Xiangliang Meng: "Who can provide me some help on how to eliminate delay and speed up the setup process."
- Next in thread: Ulrich Eckhardt: "Re: C#, why static?"
- Reply: Ulrich Eckhardt: "Re: C#, why static?"
- Reply: Will Twentyman: "Re: C#, why static?"
- Reply: Ashish Poddar: "Re: C#, why static?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|