• 0

[C#] Can you select a public variable by a variable


Question

hello, i would like to pick a public veritable such as CLASSNAME.>THIS<

where this is a variable.

public PowerObject(string _type, int _number)

{

description = UpgradeList._type;

}

where type is a name of veriable which matches what is in upgradeList.

This c# project is in XNA.

10 answers to this question

Recommended Posts

  • 0

EDIT: Disregard this post. I'll keep the content, but it's wrong. I misunderstood the question.

Depends one what "UpgradeList" is. If UpgradeList is a class name, then you'll have to make _type static as well as public. If UpgradeList is a variable name, then your code is fine as long as it's public.

HOWEVER, public variables are bad form. You should prefer properties over public variables.

  • 0

I think he is asking about Reflection. Which, yes, you can do. However depending on what you are trying to accomplish it probably isn't necessary.

Ah indeed you might be correct. I misunderstood the question. :)

  • 0

I just want to create around 20 buttons each with pre done text , values , positions of the button.

But I want the button to be a object.

Well it's not difficult to have something be an object, you just create a class that defines what that thing is and instantiate it.


class Button {
// what a button is and does goes here
}

...

var myButton = new Button(); // button object!
[/CODE]

Of course the tricky part is implementing a button that works and responds to mouse clicks. You'll have to define bounds in x and y for the button, and check whether the cursor is within these bounds when the user clicks.

  • 0
  • 0

@Majesticmerc the project is XNA so integrating windowing toolkits is not trivial.

Fair point. Does XNA not have it's own button class though? I'd have thought that would been immensely useful for UI designs, although my knowledge of XNA is limited so I wouldn't know.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • I just started using Teams (and “New” Oiutlook) at work (instead of Slack) and both are truly abysmal pieces of software.
    • If you are willing to go to approx $200, then as mentioned in your other thread I think a refurbished Pixel 8 will be a great deal that will last you for years. I recently recommended that to someone at work, he was on a strict £200 budget, which got him an excellent conditioned refurbished Pixel 8 here. He's since told me its the best phone he's ever had and feels its a massive upgrade over his old Samsung A series device. I don't know the sites which deal in refurbished devices in the US, however I’m sure you will have some options like we do here. Failing that Ebay is also quite good in my experience. If you wanted something a bit cheaper, then you could maybe go for an older Pixel 7, these will still get security updates until the end of 2027. Even after that you have good third party OS support from LineageOS. It doesn't have to be a Pixel though, you can buy many older devices for a good deal that would be better than a new $100 phone and flash LineageOS to them: https://wiki.lineageos.org/devices/
    • I don't use one drive, but then I don't use any cloud storage, not even Icloud on my mac. If I did use cloud storage, then I would not use One drive, not because there is anything wrong with it, but because I can use Icloud. The only reason I see to use one drive is if your job requires you to have access to it
    • Not built in, which is not a bad thing. There are ways of adding cloud storage to it, Dropbox is the most well know that also have a client for Linux, but there are others.
  • Recent Achievements

    • First Post
      DragonOfMercy earned a badge
      First Post
    • First Post
      bella52 earned a badge
      First Post
    • Reacting Well
      Techinmay earned a badge
      Reacting Well
    • Collaborator
      WndSks went up a rank
      Collaborator
    • One Month Later
      Sopa flores earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      495
    2. 2
      PsYcHoKiLLa
      206
    3. 3
      +Edouard
      153
    4. 4
      Steven P.
      85
    5. 5
      ATLien_0
      75
  • Tell a friend

    Love Neowin? Tell a friend!