Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
D

Dowse

@Dowse
About
Posts
7
Topics
2
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Realtime update of Label
    D Dowse

    Luc Thank you for a prompt and elegant solution to my problem. Regards Martyn

    C# database help announcement

  • Realtime update of Label
    D Dowse

    Hi all I am trying to display the value of a variable in a label. Easy enough I hear you say, but the variable can be changed by many different methods and functions, (some in dll's,) none of which trigger any specific event that I would normally use to update the label. I need the label to show the current value of the variable in 'real time.'

    public class MyClass
    {
    public DateTime datStart;
    public DateTime datNext; <======== This is the one I'm trying to show
    public int intParam1;
    public int intParam2;
    //Extra fields removed for clarity
    }

    And then in my form code:

    MyClass _myVar = new MyClass();

    I have a label called lblInformation that I would like to always show the value of _myVar.datNext.ToString() I've spent many hours trying to find a solution so any help will be very much appreciated. Thank you

    C# database help announcement

  • Enumerate Custom Class
    D Dowse

    Luc, I managed to re-work your example to give me just what I was after. Thanks for putting me on the right track:

    private void ShowData()
    {
    Type type = typeof(MyClass);
    FieldInfo[] fi = type.GetFields();

            foreach (FieldInfo info in fi)
            {
                Debug.WriteLine(info.Name + " = " + info.GetValue(varMyClass));
            }
        }
    

    varMyClass is a variable of type MyClass. Thanks to all who helped.

    modified on Thursday, July 2, 2009 1:41 PM

    C# help question

  • Enumerate Custom Class
    D Dowse

    Thomas I will read up on reflection. It seems to be what I was after. Thank you.

    C# help question

  • Enumerate Custom Class
    D Dowse

    Thank to all that responded to my post. Luc, I think I can re-work your example to give me what I was after. Thank you.

    C# help question

  • Enumerate Custom Class
    D Dowse

    Thomas Thank you for taking the time to reply to my post. I am trying to implement foreach(object o in MyClass) for reporting and (possibly) serialization.

    C# help question

  • Enumerate Custom Class
    D Dowse

    Hi all Have started writing a Class to help me with a problem in my current project and I would like to be able enumerate the variables in the Class by using a 'foreach(object o in MyClass)' in my main program. I was getting a 'MyClass does not contain a public definition for GetEnumerator' but have worked out why and I am at the point where I could really do with some help with the GetEnumerator function.

    public class MyClass : IEnumerable
    {
    public System.DateTime datStart; //Schedule start date
    public System.DateTime datEnd; //Date of final occurrence (#1/1/1900# if N/A)
    public int intParam1; //Various Uses
    public int intParam2; //Various Uses
    //Other fields remove for clarity

    //Constructor
    public MyClass()
    {
        //Set defaults for new MyClass()
        datStart = new DateTime(1900, 1, 1);
        datEnd = datStart;
        intParam1 = -1;
        intParam2 = -1;
    }
    
    IEnumerator IEnumerable.GetEnumerator()
    {
        //What goes here?
    
        return null;  //Only added this line to stop compiler error
    }
    

    }

    I know there are many, (many, many,) references to this on the web but I haven't been able to re-work any of them to solve my specific problem. Any help would be MUCH appreciated. Thank you.

    C# help question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups