Click here to Skip to main content
15,902,938 members
Home / Discussions / C#
   

C#

 
QuestionAssign a variable a series of values Pin
Wogboiii25-Apr-10 3:41
Wogboiii25-Apr-10 3:41 
AnswerRe: Assign a variable a series of values Pin
#realJSOP25-Apr-10 3:49
professional#realJSOP25-Apr-10 3:49 
GeneralRe: Assign a variable a series of values Pin
Wogboiii25-Apr-10 3:51
Wogboiii25-Apr-10 3:51 
GeneralRe: Assign a variable a series of values Pin
PIEBALDconsult25-Apr-10 5:38
mvePIEBALDconsult25-Apr-10 5:38 
AnswerRe: Assign a variable a series of values [modified] Pin
PIEBALDconsult25-Apr-10 4:03
mvePIEBALDconsult25-Apr-10 4:03 
GeneralRe: Assign a variable a series of values Pin
Wogboiii25-Apr-10 4:06
Wogboiii25-Apr-10 4:06 
GeneralRe: Assign a variable a series of values Pin
PIEBALDconsult25-Apr-10 4:20
mvePIEBALDconsult25-Apr-10 4:20 
AnswerRe: Assign a variable a series of values Pin
Moreno Airoldi25-Apr-10 4:40
Moreno Airoldi25-Apr-10 4:40 
You can get what you need with generic programming and OOP.
This is a raw example:

public class MultiVar<T>
{
    private List<T> Values = new List<T>();
    private int ValuePointer = -1;

    public MultiVar()
    {
    }

    public MultiVar(T FirstValue)
    {
        Values.Add(FirstValue);
    }

    public void AddValue(T Value)
    {
        Values.Add(Value);
    }

    public T GetValue()
    {
        if (Values.Count < 1) throw new ApplicationException("Empty value set.");
        if (++ValuePointer >= Values.Count) ValuePointer = 0;
        return Values[ValuePointer];
    }

    public static implicit operator T(MultiVar<T> Object)
    {
        return Object.GetValue();
    }
}


You can check it with:

MultiVar<int> mymultivar = new MultiVar<int>();
for (int i = 10; i < 110; i += 10) mymultivar.AddValue(i);

for (int i = 0; i < 15; i++)
{
    Console.Write(" ");
    Console.Write((int)mymultivar);
}
Console.WriteLine();


The result is:

10 20 30 40 50 60 70 80 90 100 10 20 30 40 50


Just add code to remove values, if you need it, and customize as needed.
Enjoy! Smile | :)
2+2=5 for very large amounts of 2
(always loved that one hehe!)

GeneralRe: Assign a variable a series of values Pin
harold aptroot25-Apr-10 4:42
harold aptroot25-Apr-10 4:42 
GeneralRe: Assign a variable a series of values Pin
PIEBALDconsult25-Apr-10 4:56
mvePIEBALDconsult25-Apr-10 4:56 
GeneralRe: Assign a variable a series of values Pin
Moreno Airoldi25-Apr-10 6:21
Moreno Airoldi25-Apr-10 6:21 
GeneralRe: Assign a variable a series of values Pin
Moreno Airoldi25-Apr-10 6:21
Moreno Airoldi25-Apr-10 6:21 
GeneralRe: Assign a variable a series of values Pin
harold aptroot25-Apr-10 6:26
harold aptroot25-Apr-10 6:26 
GeneralRe: Assign a variable a series of values Pin
Moreno Airoldi25-Apr-10 6:33
Moreno Airoldi25-Apr-10 6:33 
GeneralRe: Assign a variable a series of values Pin
PIEBALDconsult25-Apr-10 6:42
mvePIEBALDconsult25-Apr-10 6:42 
GeneralRe: Assign a variable a series of values Pin
Moreno Airoldi25-Apr-10 6:48
Moreno Airoldi25-Apr-10 6:48 
AnswerRe: Assign a variable a series of values Pin
Dr.Walt Fair, PE25-Apr-10 5:25
professionalDr.Walt Fair, PE25-Apr-10 5:25 
AnswerRe: Assign a variable a series of values Pin
Abhinav S25-Apr-10 6:02
Abhinav S25-Apr-10 6:02 
AnswerRe: Assign a variable a series of values Pin
Ravi Bhavnani25-Apr-10 7:40
professionalRavi Bhavnani25-Apr-10 7:40 
GeneralRe: Assign a variable a series of values Pin
Luc Pattyn25-Apr-10 8:24
sitebuilderLuc Pattyn25-Apr-10 8:24 
GeneralRe: Assign a variable a series of values Pin
Ravi Bhavnani25-Apr-10 8:36
professionalRavi Bhavnani25-Apr-10 8:36 
GeneralRe: Assign a variable a series of values Pin
PIEBALDconsult25-Apr-10 15:25
mvePIEBALDconsult25-Apr-10 15:25 
GeneralRe: Assign a variable a series of values Pin
Ravi Bhavnani25-Apr-10 15:39
professionalRavi Bhavnani25-Apr-10 15:39 
GeneralRe: Assign a variable a series of values Pin
PIEBALDconsult25-Apr-10 17:33
mvePIEBALDconsult25-Apr-10 17:33 
GeneralRe: Assign a variable a series of values Pin
Ravi Bhavnani25-Apr-10 17:51
professionalRavi Bhavnani25-Apr-10 17:51 

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.