Click here to Skip to main content
15,902,189 members
Home / Discussions / C#
   

C#

 
GeneralRe: Getting information about an object hosted on a different application Pin
dimaj11-Jun-08 7:41
dimaj11-Jun-08 7:41 
GeneralRe: Getting information about an object hosted on a different application Pin
Christian Graus11-Jun-08 8:25
protectorChristian Graus11-Jun-08 8:25 
GeneralRe: Getting information about an object hosted on a different application Pin
Christian Graus11-Jun-08 8:25
protectorChristian Graus11-Jun-08 8:25 
GeneralRe: Getting information about an object hosted on a different application Pin
dimaj11-Jun-08 8:29
dimaj11-Jun-08 8:29 
QuestionA field initializer cannot reference the non-static field, method or property... help with code snippet Pin
ssclaire11-Jun-08 6:45
ssclaire11-Jun-08 6:45 
AnswerRe: A field initializer cannot reference the non-static field, method or property... help with code snippet Pin
S. Senthil Kumar11-Jun-08 6:56
S. Senthil Kumar11-Jun-08 6:56 
GeneralRe: A field initializer cannot reference the non-static field, method or property... help with code snippet Pin
ssclaire11-Jun-08 8:35
ssclaire11-Jun-08 8:35 
AnswerSome Progress... Update Pin
ssclaire11-Jun-08 7:08
ssclaire11-Jun-08 7:08 
Okay, I think it is the "cannot reference the non-static" part of the error which is relevant.

If I move the Main() code into a class:
class MyClass
{
    Array colorValues = Enum.GetValues(typeof(ColorType));
    Array shapeValues = Enum.GetValues(typeof(ShapeType));
    Polygon[] allPolygons = new Polygon[colorValues.Length * shapeValues.Length];

    public MyClass()
    {
        int index = 0;
        foreach (ColorType color in colorValues)
        {
            foreach (ShapeType shape in shapeValues)
            {
                allPolygons[index] = new Polygon(color, shape);
                Console.WriteLine(allPolygons[index]);
                index++;
            }
        }
    }
}

...and call it from Main()
static void Main(string[] args)
{
    MyClass myClass = new MyClass();
}

I get the error. But how do I work around that? How would I create the private allPolygons array? What am I actually doing wrong?
GeneralRe: Some Progress... Update Pin
Christian Graus11-Jun-08 7:19
protectorChristian Graus11-Jun-08 7:19 
GeneralRe: Some Progress... Update Pin
S. Senthil Kumar11-Jun-08 8:27
S. Senthil Kumar11-Jun-08 8:27 
AnswerRe: A field initializer cannot reference the non-static field, method or property... help with code snippet Pin
Christian Graus11-Jun-08 7:08
protectorChristian Graus11-Jun-08 7:08 
QuestionCompiler Error Message: CS1519: Invalid token 'foreach' in class, struct, or interface member declaration Pin
Marvin A. Lee II11-Jun-08 6:17
Marvin A. Lee II11-Jun-08 6:17 
AnswerRe: Compiler Error Message: CS1519: Invalid token 'foreach' in class, struct, or interface member declaration Pin
leppie11-Jun-08 6:21
leppie11-Jun-08 6:21 
GeneralRe: Compiler Error Message: CS1519: Invalid token 'foreach' in class, struct, or interface member declaration Pin
Marvin A. Lee II11-Jun-08 11:51
Marvin A. Lee II11-Jun-08 11:51 
AnswerRe: Compiler Error Message: CS1519: Invalid token 'foreach' in class, struct, or interface member declaration Pin
S. Senthil Kumar11-Jun-08 6:22
S. Senthil Kumar11-Jun-08 6:22 
AnswerRe: Compiler Error Message: CS1519: Invalid token 'foreach' in class, struct, or interface member declaration Pin
leppie11-Jun-08 6:23
leppie11-Jun-08 6:23 
QuestionCode Generation competition Article Submission problem. Pin
hdv21211-Jun-08 6:06
hdv21211-Jun-08 6:06 
AnswerRe: Code Generation competition Article Submission problem. Pin
leppie11-Jun-08 6:19
leppie11-Jun-08 6:19 
GeneralRe: Code Generation competition Article Submission problem. Pin
hdv21211-Jun-08 6:23
hdv21211-Jun-08 6:23 
GeneralRe: Code Generation competition Article Submission problem. Pin
leppie11-Jun-08 6:25
leppie11-Jun-08 6:25 
AnswerRe: Code Generation competition Article Submission problem. Pin
Giorgi Dalakishvili11-Jun-08 6:58
mentorGiorgi Dalakishvili11-Jun-08 6:58 
QuestionShould I use new for a string? [Solved] Pin
Hamed Musavi11-Jun-08 5:59
Hamed Musavi11-Jun-08 5:59 
AnswerRe: Should I use new for a string? Pin
leppie11-Jun-08 6:06
leppie11-Jun-08 6:06 
GeneralRe: Should I use new for a string? Pin
Hamed Musavi11-Jun-08 6:12
Hamed Musavi11-Jun-08 6:12 
GeneralRe: Should I use new for a string? Pin
leppie11-Jun-08 6:18
leppie11-Jun-08 6:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.