Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 21st, 2004, 03:42 PM
Authorized User
 
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default working with enums & properties

Hello,

Sorry for the question, but I am a beginner, and I need to solve this code fast:

I have the next enumeration:

public enum GameState {playing, win, lose}

I need to create a property State only for reading and I don't know how to do it.

Also I don't know how to assign a value to GameState.

Anybody can help me, please?

Thanks

-------------------------------
World only exists into your mind.
 
Old January 21st, 2004, 03:57 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Usually, in a class you would create a property and a private internal like this:

public class myClass{
    private GameState _myGameState;
    public GameState State{
        get{return _myGameState;}
        set{_myGameState = value;}
    }
}

If you want it to be readonly then you can just remove the "set" line. But you'll need something to set the value. Without knowing how you intended to use the property, it's hard to suggest how to set it aside from making the property read/write.

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old January 22nd, 2004, 04:16 AM
Authorized User
 
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello,

I think I solved it:

public enum EstadoPartida {Jugando, Ganada, Perdida};
private EstadoPartida estado;
public EstadoPartida Estado
{
  get
  {
    return Estado;
  }
}

 ...

estado = EstadoPartida.Jugando;

Thanks, planoie, but I needed something like above.


-------------------------------
World only exists into your mind.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Access properties & methods from a WebService sloesch VB.NET 8 January 24th, 2006 02:02 PM
Object Properties & document.activeElement interrupt Javascript How-To 4 April 21st, 2005 03:49 PM
Image Properties & CSS TSEROOGY CSS Cascading Style Sheets 2 October 10th, 2004 09:26 PM
Enums for accounts??? rcarter BOOK: ASP.NET Website Programming Problem-Design-Solution 3 November 8th, 2003 12:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.