Click here to Skip to main content
15,894,539 members
Home / Discussions / C#
   

C#

 
QuestionBuilding Regular Expressions Pin
jorgearmindo14-May-06 0:33
jorgearmindo14-May-06 0:33 
AnswerRe: Building Regular Expressions Pin
User 665814-May-06 4:17
User 665814-May-06 4:17 
Questionget from DB to combobox Pin
moranhaim14-May-06 0:26
moranhaim14-May-06 0:26 
AnswerRe: get from DB to combobox Pin
NaNg1524114-May-06 1:19
NaNg1524114-May-06 1:19 
GeneralRe: get from DB to combobox Pin
moranhaim14-May-06 3:12
moranhaim14-May-06 3:12 
Questionhow to Break when a value of object is changed ? Pin
kumar.bs13-May-06 22:47
kumar.bs13-May-06 22:47 
AnswerRe: how to Break when a value of object is changed ? Pin
Guffa13-May-06 23:08
Guffa13-May-06 23:08 
Questionusing explicit conversion operators for arrays? Pin
SimonS13-May-06 22:05
SimonS13-May-06 22:05 
I'm trying to establish a good way of doing something before finalising my codegen.

Below is an example:

private void Form1_Load(object sender, EventArgs e)
        {
            Employee emp = ReallyCoolFuncSingle();
            //MessageBox.Show(emp.Age + " " + emp.BasePerson.PersonName);
        }

        
        public Employee ReallyCoolFuncSingle()
        {
            Employee e = new Employee();
            Person p = CoolFuncSingle();

            e = (Employee)p;
            e.Age = "100";
            
            return e;
        }
        //public Employee[] ReallyCoolFuncArray()
        //{
        //    Employee[] e;
        //    Person[] p = CoolFuncArray();

        //    e = (Employee[])p;
        //    //e.Age = "100";

        //    return e;
        //}


        public Person CoolFuncSingle()
        {
            Person p = new Person();
            p.PersonName="billy bob";
            return p;
        }
        public Person[] CoolFuncArray()
        {
            Person[] p = new Person[2];
            p[0] = new Person();
            p[1] = new Person();
            p[0].PersonName = "billy bob";
            p[1].PersonName = "frank";

            return p;
        }



        public class Person
        {
            private string _PersonName;

            public string PersonName
            {
                get { return _PersonName; }
                set { _PersonName = value; }
            }

            public static explicit operator Person(Employee e)
            {
                Person p = new Person();
                p.PersonName = e.PersonName;
                //e.Age = 100;
                return p;
            }
	
        }
        public class Employee// : Person
        {
            //private Person _BasePerson;

            //public Person BasePerson
            //{
            //    get { return _BasePerson; }
            //    set { _BasePerson = value; }
            //}
	
            #region person stuff
            private string _PersonName;

            public string PersonName
            {
                get { return _PersonName; }
                set { _PersonName = value; }
            }
            #endregion

            private string _Age;

            public string Age
            {
                get { return _Age; }
                set { _Age = value; }
            }

            public static explicit operator Employee(Person p)
            {
                Employee e = new Employee();
                e.PersonName = p.PersonName;
                //e.Age = 100;
                return e;
            }
        }


In essence, I'm trying to modify the Person object returned from some functions and return a super class of some sort - whether actually derived or not is not the issue.
It's a wrap and modify type of pattern.

The code above shows a few attempts.

Basically it all works fine for single objects (managed to get around the explicit operator restrictions), but won't work for arrays.

Any ideas?

Cheers,
Simon


> blog:: brokenkeyboards
> what I think of the OPTIONAL keyword in VB.NET? :: here
> CV :: PDF
> skype :: SimonMStewart

AnswerRe: using explicit conversion operators for arrays? Pin
Robert Rohde13-May-06 22:23
Robert Rohde13-May-06 22:23 
GeneralRe: using explicit conversion operators for arrays? Pin
leppie13-May-06 23:46
leppie13-May-06 23:46 
GeneralRe: using explicit conversion operators for arrays? Pin
Robert Rohde14-May-06 3:52
Robert Rohde14-May-06 3:52 
GeneralRe: using explicit conversion operators for arrays? Pin
SimonS14-May-06 23:21
SimonS14-May-06 23:21 
GeneralDynamic string conversion in c# Pin
Justin Hummel13-May-06 22:05
Justin Hummel13-May-06 22:05 
GeneralRe: Dynamic string conversion in c# Pin
Robert Rohde13-May-06 22:16
Robert Rohde13-May-06 22:16 
GeneralRe: Dynamic string conversion in c# Pin
Justin Hummel13-May-06 22:23
Justin Hummel13-May-06 22:23 
Question16-bit image Pin
IMClimatology13-May-06 18:53
IMClimatology13-May-06 18:53 
QuestionHow to display drivers in combobox? Pin
cshong13-May-06 18:53
cshong13-May-06 18:53 
QuestionUSB PNP Pin
rudy.net13-May-06 14:24
rudy.net13-May-06 14:24 
AnswerRe: USB PNP Pin
rudy.net13-May-06 16:10
rudy.net13-May-06 16:10 
QuestionIComparable interface *2 Pin
eggie513-May-06 14:23
eggie513-May-06 14:23 
AnswerRe: IComparable interface *2 Pin
led mike13-May-06 17:05
led mike13-May-06 17:05 
AnswerRe: IComparable interface *2 Pin
Josh Smith13-May-06 17:44
Josh Smith13-May-06 17:44 
Question[Access database] how to get the last row inserted? Pin
Susuko13-May-06 12:55
Susuko13-May-06 12:55 
AnswerRe: [Access database] how to get the last row inserted? Pin
NaNg1524113-May-06 17:52
NaNg1524113-May-06 17:52 
AnswerRe: [Access database] how to get the last row inserted? Pin
mav.northwind14-May-06 1:09
mav.northwind14-May-06 1:09 

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.