0

In code below, when you access the style property, I want it to be accepting parameter-type: top, left, width etc... so it'll be inserted from intellisense firstly not to give you a chance to accidentally misspell, forget or just for the sake of "automation" or however we call it, to be in the intellisense as an option to select from.

Instead of:

objectID.Style.Add("property", "Value"); 

you get offered by the available properties:

objectID.Style.Add(Top, "here you will hardcode manually"); 
objectID.Style.Add(Left, "100px");
objectID.Style.Add(Width, "230px"); // but every parameter that represents an object property 
        //such as: Top, Left Etc' ... i would like to have it as an option opposed, to hard coding it

I will be happy to give more detailed ideas of what I was thinking of... with another example:

    DateTime fullDate = DateTime.Now;
    string ddays = fullDate.Day.ToString();
    string dmonth = fullDate.Month.ToString();
    string dyear = fullDate.Year.ToString();

How can I, with the code above, that takes parts of date and stores each into a string representing the date, Day, Month, Year Then to put it in a class so I can reuse it on other codes:

Label1.Text = Day; Label2.Text = Month; Label3.Text = Year;

Again what I want to achieve is that those values will be inside intellisense when ever the App_Code has the so called "Class" we have built...

Same as with the style properties in first part of that thread.

As I am new to oop I would like to better comprehend from that example what are field properties Types (your own) and classes, from this perspective too (those codes above) I will really appreciate the right / detailed answer, with hope that one day, I would be able to help others too...

1 Answers1

1

For your first example, an enum is perfect:

public enum StyleOptions { Top, Left, Width, etc }

objectID.Style.Add(StyleOptions.Top, "here you will hardcode manually");

For the second one, I'd recommend passing around a DateTime instead of separate strings. If you then want to show the separate parts in separate labels, then in the page/form/user control that has the boxes, do your Label1.Text = fullDate.Day.ToString(); (etc.) code.

DateTime (a struct) and StyleOptions (an enum) are both types. classes are also types, (and are the most common types you'll see in C#) but I'm not sure which classes you're using here (whatever contains the methods where you've got your code snippets is almost certainly a class you've made). Fields are essentially variables that belong to instances of types (if non-static), or to the type itself (if static). Properties are accessed like fields, but are defined using methods, so you can do things like lazy-loading and notify when properties changed on get and set. If that's not too clear, see Difference between Property and Field in C# 3.0+, and Fields and Properties documentation.

Community
  • 1
  • 1
Tim S.
  • 52,076
  • 7
  • 84
  • 114
  • i would like to thank the kind answer of Mr Tim S. although i didn't yet understand i'll go through that code , i'll implement it, read your post again ... then hopfully better comprehend ... Thanks a lot ppl! –  Jun 09 '12 at 22:05