Click here to Skip to main content
15,899,475 members
Home / Discussions / C#
   

C#

 
GeneralRe: quickest and easiest way to share data (C dll & .net dll) Pin
Nick Parker24-Nov-04 11:08
protectorNick Parker24-Nov-04 11:08 
GeneralRe: quickest and easiest way to share data (C dll & .net dll) Pin
asaddsada24-Nov-04 11:53
sussasaddsada24-Nov-04 11:53 
Generalweb services update database using dataset Pin
Don Jonathan24-Nov-04 11:00
sussDon Jonathan24-Nov-04 11:00 
GeneralRe: web services update database using dataset Pin
Heath Stewart24-Nov-04 14:40
protectorHeath Stewart24-Nov-04 14:40 
Questiondynamic acces to class variables? Pin
TyronX24-Nov-04 8:25
TyronX24-Nov-04 8:25 
AnswerRe: dynamic acces to class variables? Pin
TyronX24-Nov-04 8:36
TyronX24-Nov-04 8:36 
GeneralRe: dynamic acces to class variables? Pin
DavidNohejl24-Nov-04 14:13
DavidNohejl24-Nov-04 14:13 
AnswerRe: dynamic acces to class variables? Pin
Heath Stewart24-Nov-04 8:55
protectorHeath Stewart24-Nov-04 8:55 
You can use reflection to enumerate types and their members (properties, fields, and methods). Read Discovering Type Information at Runtime[^] in the .NET Framework SDK.

Note that these aren't "variables". Variables - in practically any language - are temporary memory addresses to store information in a particular function or method (methods are functions declared for a class or other structure). You can also have global variables.

To enumerate properties on a class, for example (since you typically shouldn't expose fields publicly; you have little control over what gets assigned and can't validate the data):
using System;
using System.Reflection;
 
class Person
{
  static void Main()
  {
    Person p = new Person("Heath", DateTime.Parse("08/07/1978"));
    Reflect(p);
  }
 
  static void Reflect(Person p)
  {
    PropertyInfo[] props = p.GetType().GetProperties(
      BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
    if (props != null)
    {
      foreach (PropertyInfo prop in props)
      {
        object value = prop.GetValue(p, null);
        Console.WriteLine("{0} ({1}) = {2}", prop.Name, prop.PropertyType,
            value);
      }
    }
  }
 
  Person(string name, DateTime birthday)
  {
    this.name = name;
    this.birthday = birthday;
  }
 
  string name;
  DateTime birthday;
 
  public string Name
  {
    get { return name; }
    set
    {
      if (value == null) throw new ArgumentNullException();
      name = value;
    }
  }
 
  public DateTime Birthday
  {
    get { return birthday; }
    set { birthday = value; }
  }
}


This posting is provided "AS IS" with no warranties, and confers no rights.

Software Design Engineer
Developer Division Sustained Engineering
Microsoft

[My Articles] [My Blog]
GeneralDoubleClick Event on a Label Pin
mlamb24-Nov-04 7:49
mlamb24-Nov-04 7:49 
GeneralRe: DoubleClick Event on a Label Pin
Heath Stewart24-Nov-04 8:44
protectorHeath Stewart24-Nov-04 8:44 
Generalproblem with GraphicsPath Pin
bernd.salewski24-Nov-04 7:49
bernd.salewski24-Nov-04 7:49 
GeneralRe: problem with GraphicsPath Pin
Heath Stewart24-Nov-04 9:01
protectorHeath Stewart24-Nov-04 9:01 
GeneralRe: problem with GraphicsPath Pin
bernd.salewski24-Nov-04 9:14
bernd.salewski24-Nov-04 9:14 
GeneralRe: problem with GraphicsPath Pin
Heath Stewart24-Nov-04 10:06
protectorHeath Stewart24-Nov-04 10:06 
GeneralRe: problem with GraphicsPath Pin
bernd.salewski24-Nov-04 10:51
bernd.salewski24-Nov-04 10:51 
GeneralI found my mistake!!! Pin
bernd.salewski24-Nov-04 11:50
bernd.salewski24-Nov-04 11:50 
Generalsummations Pin
cma2324-Nov-04 7:18
cma2324-Nov-04 7:18 
GeneralRe: summations Pin
Heath Stewart24-Nov-04 8:45
protectorHeath Stewart24-Nov-04 8:45 
GeneralRe: summations Pin
cma2324-Nov-04 9:16
cma2324-Nov-04 9:16 
GeneralRe: summations Pin
Heath Stewart24-Nov-04 10:09
protectorHeath Stewart24-Nov-04 10:09 
GeneralRemoting Problems ... Pin
Paebbels24-Nov-04 6:23
Paebbels24-Nov-04 6:23 
GeneralRe: Remoting Problems ... Pin
Paebbels25-Nov-04 9:07
Paebbels25-Nov-04 9:07 
QuestionFind HttpChannel??? Pin
Snowjim24-Nov-04 4:42
Snowjim24-Nov-04 4:42 
AnswerRe: Find HttpChannel??? Pin
Stefan Troschuetz24-Nov-04 5:10
Stefan Troschuetz24-Nov-04 5:10 
GeneralRe: Find HttpChannel??? Pin
Snowjim24-Nov-04 5:19
Snowjim24-Nov-04 5:19 

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.