• 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

    • Microsoft wants to end printer driver headaches with Windows Ready Print by Usama Jawad A few days ago, Microsoft released Windows 11 Experimental build 26300.8553, bringing a ton of enhancements such as Start menu customization, search improvements, Taskbar polish, and other minor UI tweaks. Another relatively major enhancement snuck deep within the change log was related to upgrades to the Windows printing experience. Now, Microsoft has shared more details about these benefits. For starters, Microsoft has renamed its Modern Print Platform to Windows Ready Print. The company believes that this name highlights its shift in strategy, which now focuses on modernizing, securing, and streamlining the printing experience for Windows devices. Some of the upgrades present in Windows Ready Print have already been seeded to customers and partners. This includes ending support for third-party printer drivers via Windows Update and transitioning towards the Internet Printing Protocol (IPP) and the native Windows IPP printer driver. In line with these changes, new printer installations will default to Windows Ready Print on eligible devices starting from July 2026. However, Microsoft recognizes that not all environments will be able to migrate to this platform immediately, so it will allow users to choose between installing the printer via Windows Ready Print or the traditional OEM process. Users will be able to toggle this configuration through Settings > Bluetooth & Devices > Printers & Scanners > Printer preferences. This control applies only to new printer installations, and its functionality can also be modified via Group Policy as follows: Launch Group Policy Editor Navigate to Local Computer Policy -> Administrative Templates -> Printers Find and select 'Configure Windows Ready Print driver ranking' -> double click to open it Select 'Enabled' (if you wish to enable Windows Ready Print driver selection) or 'Disabled' (if you wish to explicitly disable Windows Ready Print driver selection). Select Apply Select OK Similarly, if you set up Windows protected print mode through the same setting in Windows 11, it will also default to using Windows Ready Print exclusively. Microsoft hopes that these improvements will help eradicate dependency on OEM-specific driver installation processes and simplify printer installations. We'll likely find out more about other tangible benefits in the coming months.
    • Hey what's about the proton vpn firefox extension ? It's not working today
    • On what though? Not Ray Tracing.
    • Agreed, but now my muscle memory immediately creates a layer for each text portion, so editing is made a little easier.
    • Happy for him, it is one of the first apps I install on a new Windows machine, been using it for years!
  • Recent Achievements

    • One Year In
      Primer1st earned a badge
      One Year In
    • Experienced
      JayZJay went up a rank
      Experienced
    • Reacting Well
      Sir_Timbit earned a badge
      Reacting Well
    • Week One Done
      rubentuben8 earned a badge
      Week One Done
    • Week One Done
      ARaclen earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      514
    2. 2
      PsYcHoKiLLa
      229
    3. 3
      Edouard
      137
    4. 4
      ATLien_0
      87
    5. 5
      Steven P.
      81
  • Tell a friend

    Love Neowin? Tell a friend!