愚蠢的问题..请帮忙! [英] dumb question.. please help!

查看:60
本文介绍了愚蠢的问题..请帮忙!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨peeps


好​​的,所以我想我会在VS2k5中制作一个控制台应用程序...我没有

多年来写了任何Windows应用程序,更不用说dos应用程序(已经是网络编程)

而且我遇到了一个愚蠢的错误...


非静态字段,方法或属性需要对象引用

[propertyname]"


这是在我的主函数中发生的...


public static void Main(string [] args)

{

DisplayHeader();

}


显示标题的定义如下......

public void DisplayHeader()

{

Console.WriteLine(" hello!");

}


发生了什么事 - 我''我试图让一切都变得静止,但我得到了错误。

我试过制作主要的非主流,但它也不喜欢这样。我是什么?b $ b缺少了什么?这也发生在班级变量上!?


帮助!


Dan

解决方案

您需要将方法''DisplayHeader''设为静态或创建一个

类的实例:


例如

///< summary>

/// Class1的摘要说明。

///< / summary>

class Class1

{

///< summary>

///主要入口点申请。

///< / summary>

[STAThread]

static void Main(string [] args)

{

Class1 instance = new Class1();

instance.DisplayHeader();

}


public void DisplayHeader()

{

Console.WriteLine(" hello!");

} < br $>
}




//< summary>

/// Class1的摘要说明。

///< / summary>

class Class1

{

///< summary>

///应用程序的主要入口点。

///< / summary>

[STAThread]

static void Main(string [] args)

{

DisplayHeader();

}

public static void DisplayHeader()

{

Console.WriteLine(" hello!");

}

}


HTH


Ollie Riches

an@musoswire.com >在消息中写道

news:60 ********************************** @ microsof t.com ...

嗨peeps

好的,所以我想我会在VS2k5中制作一个控制台应用程序...我多年来没有写过任何Windows应用程序,更不用说dos应用程序(已经是web
编程)
而且我遇到了一个愚蠢的错误...

非静态字段,方法或
属性需要对象引用
[propertyname]"

这是在我的主要功能中发生的......

public static void Main(string [] args)
{
DisplayHeader();
}

显示标题的定义如下。 ..

public void DisplayHeader()
{
Console.WriteLine(" hello!");
}

什么我正在尝试让一切都变得静止,但是我得到了错误。
我已经尝试过制作主要的非主流,但它也不喜欢这样。什么是
我失踪了?这也发生在班级变量上!?

帮助!


请原谅我......我不明白为什么当2个函数

属于同一类时我必须这样做?当然main()执行的事实意味着

必须有一个该类的实例?!


" Ollie Riches"写道:

您需要将方法''DisplayHeader''设为静态或创建该类的实例:

例如

///< summary>
/// Class1的摘要说明。
///< / summary>
class Class1
{
///< summary>
///应用程序的主要入口点。
///< / summary>
[STAThread]
static void Main (string [] args)
{
Class1 instance = new Class1();
instance.DisplayHeader();
}
公共无效DisplayHeader( )
{
Console.WriteLine(" hello!");
}
}



/ /< summary>
/// Class1的摘要说明。
///< / summary>
class Class1
{
///< summary> ;
///应用程序的主要入口点。
///< / summary>
[STAThread ]
static void Main(string [] args)
{
DisplayHeader();
}
public static void DisplayHeader()
{
Console.WriteLine(" hello!");
}
}

HTH

Ollie Riches

an@musoswire.com >在消息中写道
新闻:60 ********************************** @ microsof t.com。 ..

嗨peeps

好的,所以我想我会在VS2k5中制作一个控制台应用程序...我
避风港'' t
多年来编写任何Windows应用程序,更不用说dos应用程序(已经是web
编程)
我发现了一个愚蠢的错误......

;非静态字段,方法或
属性需要对象引用
[propertyname]"

这是在我的主要功能中发生的......

public static void Main(string [] args)
{
DisplayHeader();
}

显示标题的定义如下...

public void DisplayHeader()
{
Console.WriteLine(" hello!");
}

怎么回事on - 我试过让一切都变得静止,但是我得到了错误。
我已经尝试过制作主要的非主流,但它也不喜欢。什么是
我失踪了?这也发生在班级变量上!?

帮助!





dhnriverside写道:

原谅我...我不明白为什么我必须这样做2个功能是否属于同一类?当然main()正在执行的事实意味着
必须有一个该类的实例?!


不,因为main()被声明为静态!

Ollie Riches写道:

您需要将方法''DisplayHeader''设为静态或创建该类的实例:

例如

///< summary>
/// Class1的摘要说明。
///< / summary>
class Class1
{
///< summary>
///应用程序的主要入口点。
///< / summary>
[STAThread]
static void Main (string [] args)
{
Class1 instance = new Class1();
instance.DisplayHeader();
}
公共无效DisplayHeader( )
{
Console.WriteLine(" hello!");
}
}



/ /< summary>
/// Class1的摘要说明。
///< / summary>
class Class1
{
///< summary> ;
///应用程序的主要入口点。
///< / summary>
[STAThread]
static void Main(string [] args)
{
DisplayHeader();
}
public static void DisplayHeader()
{
Console.WriteLine(" hello!");
}


HTH

Ollie Riches

< a href =mailto:an@musoswire.com> an@musoswire.com >在消息中写道
新闻:60 ********************************** @ microsof t.com。 ..

嗨peeps

好的,所以我想我会在VS2k5中制作一个控制台应用程序...我
避风港'' t
多年来编写任何Windows应用程序,更不用说dos应用程序(已经是web
编程)
我发现了一个愚蠢的错误......

;非静态字段,方法或
属性需要对象引用
[propertyname]"

这是在我的主要功能中发生的......

public static void Main(string [] args)
{
DisplayHeader();
}

显示标题的定义如下...

public void DisplayHeader()
{
Console.WriteLine(" hello!");
}

怎么回事on - 我试过让一切都变得静止,但是我得到了错误。
我已经尝试过制作主要的非主流,但它也不喜欢。什么是
我失踪了?这也发生在班级变量上!?

Dan





Hi peeps

Ok, so I thought I''d have a go at making a console app in VS2k5... I haven''t
written any windows apps for years, let alone dos apps (been web programming)
and I''ve hit a dumb error...

"An object reference is required for the nonstatic field, method or property
[propertyname]"

This is occuring in my main function...

public static void Main(string[] args)
{
DisplayHeader();
}

Display header is defined like so...

public void DisplayHeader()
{
Console.WriteLine("hello!");
}

What''s going on - I''ve tried making everything static, but I get errors.
I''ve tried making main nonstatic, but it didn''t like that either. What am I
missing? This also happens on class-wide variables as well!?

Help!

Dan

解决方案

You either need to make the method ''DisplayHeader'' static or create an
instance of the class:

e.g.
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Class1 instance = new Class1();
instance.DisplayHeader();
}

public void DisplayHeader()
{
Console.WriteLine("hello!");
}
}
or

// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
DisplayHeader();
}
public static void DisplayHeader()
{
Console.WriteLine("hello!");
}
}

HTH

Ollie Riches

an@musoswire.com> wrote in message
news:60**********************************@microsof t.com...

Hi peeps

Ok, so I thought I''d have a go at making a console app in VS2k5... I
haven''t
written any windows apps for years, let alone dos apps (been web
programming)
and I''ve hit a dumb error...

"An object reference is required for the nonstatic field, method or
property
[propertyname]"

This is occuring in my main function...

public static void Main(string[] args)
{
DisplayHeader();
}

Display header is defined like so...

public void DisplayHeader()
{
Console.WriteLine("hello!");
}

What''s going on - I''ve tried making everything static, but I get errors.
I''ve tried making main nonstatic, but it didn''t like that either. What am
I
missing? This also happens on class-wide variables as well!?

Help!

Dan



Forgive me... I don''t understand why I have to do that when the 2 functions
are in the same class? Surely the fact that main() is executing means that
there must be an instance of that class already?!

"Ollie Riches" wrote:

You either need to make the method ''DisplayHeader'' static or create an
instance of the class:

e.g.
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Class1 instance = new Class1();
instance.DisplayHeader();
}

public void DisplayHeader()
{
Console.WriteLine("hello!");
}
}
or

// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
DisplayHeader();
}
public static void DisplayHeader()
{
Console.WriteLine("hello!");
}
}

HTH

Ollie Riches

an@musoswire.com> wrote in message
news:60**********************************@microsof t.com...

Hi peeps

Ok, so I thought I''d have a go at making a console app in VS2k5... I
haven''t
written any windows apps for years, let alone dos apps (been web
programming)
and I''ve hit a dumb error...

"An object reference is required for the nonstatic field, method or
property
[propertyname]"

This is occuring in my main function...

public static void Main(string[] args)
{
DisplayHeader();
}

Display header is defined like so...

public void DisplayHeader()
{
Console.WriteLine("hello!");
}

What''s going on - I''ve tried making everything static, but I get errors.
I''ve tried making main nonstatic, but it didn''t like that either. What am
I
missing? This also happens on class-wide variables as well!?

Help!

Dan





dhnriverside wrote:

Forgive me... I don''t understand why I have to do that when the 2 functions
are in the same class? Surely the fact that main() is executing means that
there must be an instance of that class already?!
No, because main() is declared static!

"Ollie Riches" wrote:

You either need to make the method ''DisplayHeader'' static or create an
instance of the class:

e.g.
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Class1 instance = new Class1();
instance.DisplayHeader();
}

public void DisplayHeader()
{
Console.WriteLine("hello!");
}
}
or

// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
DisplayHeader();
}
public static void DisplayHeader()
{
Console.WriteLine("hello!");
}
}

HTH

Ollie Riches

an@musoswire.com> wrote in message
news:60**********************************@microsof t.com...

Hi peeps

Ok, so I thought I''d have a go at making a console app in VS2k5... I
haven''t
written any windows apps for years, let alone dos apps (been web
programming)
and I''ve hit a dumb error...

"An object reference is required for the nonstatic field, method or
property
[propertyname]"

This is occuring in my main function...

public static void Main(string[] args)
{
DisplayHeader();
}

Display header is defined like so...

public void DisplayHeader()
{
Console.WriteLine("hello!");
}

What''s going on - I''ve tried making everything static, but I get errors.
I''ve tried making main nonstatic, but it didn''t like that either. What am
I
missing? This also happens on class-wide variables as well!?

Help!

Dan





这篇关于愚蠢的问题..请帮忙!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆