Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(object) is a 'field' but is used like a 'type'

Tags:

c#

asp.net

My intellisense is giving me the error: 'ClassLibrary1.GetTimeZone.myWorldTime' is a 'field' but is used like a 'type'

Any idea what I'm doing wrong?

My code

!Object Browser for the class1 My code

like image 874
iKode Avatar asked Jan 18 '12 10:01

iKode


People also ask

Can a field be an object?

Can objects be fields too? @Ahmad No, a field can't be an "object". it can be a reference to an object.

How do you check if an object is a specific type?

To determine whether an object is a specific type, you can use your language's type comparison keyword or construct.

What is type object in C#?

The object type is an alias for System. Object in . NET. In the unified type system of C#, all types, predefined and user-defined, reference types and value types, inherit directly or indirectly from System.

What type is a class C#?

Classes are reference types that hold the object created dynamically in a heap. All classes have a base type of System. Object. The default access modifier of a class is Internal.


2 Answers

You need to put the line in error in a class constructor or a method.

like image 57
Louis Kottmann Avatar answered Oct 29 '22 19:10

Louis Kottmann


LoadData is a static method. You call it on the type, not an instance.

ChaosSoftware.WorldTime.LoadData("worldtime.xml");

This needs to be placed inside a method in order to execute (constructor or other method).

Additionally, though not the reason for the error, you should use " to delimit a string. In C#, single quotes are for character literals (that is, single characters). What you have will not compile.

like image 22
Oded Avatar answered Oct 29 '22 21:10

Oded