Click here to Skip to main content
15,861,168 members
Home / Discussions / C#
   

C#

 
AnswerRe: Looking to Learn Programming better Need help please. Pin
#realJSOP16-Dec-09 8:59
mve#realJSOP16-Dec-09 8:59 
GeneralRe: Looking to Learn Programming better Need help please. Pin
Pete O'Hanlon16-Dec-09 9:02
subeditorPete O'Hanlon16-Dec-09 9:02 
GeneralRe: Looking to Learn Programming better Need help please. Pin
Luc Pattyn16-Dec-09 9:43
sitebuilderLuc Pattyn16-Dec-09 9:43 
GeneralRe: Looking to Learn Programming better Need help please. Pin
PIEBALDconsult16-Dec-09 10:35
mvePIEBALDconsult16-Dec-09 10:35 
GeneralRe: Looking to Learn Programming better Need help please. Pin
Luc Pattyn16-Dec-09 11:02
sitebuilderLuc Pattyn16-Dec-09 11:02 
GeneralRe: Looking to Learn Programming better Need help please. Pin
PIEBALDconsult16-Dec-09 11:50
mvePIEBALDconsult16-Dec-09 11:50 
AnswerRe: Looking to Learn Programming better Need help please. Pin
BillWoodruff16-Dec-09 18:17
professionalBillWoodruff16-Dec-09 18:17 
QuestionContinued Values Collection/List/Dictionary [modified] Pin
Som Shekhar16-Dec-09 7:48
Som Shekhar16-Dec-09 7:48 
I am learning further in C# and came across a special requirement of collections. I wonder if such implementations exists.

I need a list with a key and multiple values. After the first entry, next entries can be partial only to denote a change. Something like this:

index	value1	value2	value3		Result		value1	value2	value3
1	100	200	300		-		100	200	300
2			200		-		100	200	200
3	150		300		-		150	200	300
4		250			-		150	250	300
5	100	200			-		100	200	300


This can be achieved using DataTable and using select statements/compute etc. But, is there a simpler option available? Speed is the key here.

----------------------------Question Modified----------------------------------

Please understand that creating a list/dictionary/array/hashtable is not the problem here. Storing the data is easy. This could be done using numeric Key/Index (I can manage to keep indexes of the keys also).

The idea is to be able to look for the last fetched value against each key. The problem comes when I want to retrieve he value without having to loop again. Look at the same example with modified index values.

index	value1	value2	value3		Result		value1	value2	value3
100	100	200	300		-		100	200	300
200			200		-		100	200	200
300	150		300		-		150	200	300
400		250			-		150	250	300
500	100	200			-		100	200	300


Consider the next step. if I want to find out the value for key 250, I would want to look for 200, and then find results for it.

Is it possible without going through loops again?

Current Solution:

I created a class as:

class DataClass
{
    int Value1; int Value2; int Value3
    int ValueIndex1; int ValueIndex2; int ValueIndex3;
}


Then for each entry done, I need to run the loop once to find out the last index for which entry was done against the value and store it.

Dictionary<int, DataClass> entries = new Dictionary<int, DataClass>();
entries.Add(100, new DataClass(100,200,300, 100,100,100);
entries.Add(200, new DataClass(  0,150,  0, 100,200,100);
entries.Add(300, new DataClass(  0,  0,250, 100,200,300);
entries.Add(400, new DataClass(150,  0,  0, 400,200,300);
entries.Add(500, new DataClass(  0,200,  0, 400,500,300);


Now, whenever i need to look for 250, i search for closest smaller key (here that is 200). find values. whatever is available is taken as it is. For all others, find the key in the same record and get the new entries.

This solution works for the first time entries. However it creates problems when an entry is inserted in between. Another logic needs to be built in between.

Can there be something faster than this?
----------------------------------

modified on Thursday, December 17, 2009 12:58 AM

AnswerRe: Continued Values Collection/List/Dictionary Pin
#realJSOP16-Dec-09 9:04
mve#realJSOP16-Dec-09 9:04 
GeneralRe: Continued Values Collection/List/Dictionary Pin
Som Shekhar16-Dec-09 19:16
Som Shekhar16-Dec-09 19:16 
AnswerRe: Continued Values Collection/List/Dictionary Pin
Eddy Vluggen16-Dec-09 10:19
professionalEddy Vluggen16-Dec-09 10:19 
GeneralRe: Continued Values Collection/List/Dictionary Pin
Som Shekhar16-Dec-09 19:15
Som Shekhar16-Dec-09 19:15 
GeneralRe: Continued Values Collection/List/Dictionary Pin
Eddy Vluggen16-Dec-09 21:13
professionalEddy Vluggen16-Dec-09 21:13 
GeneralRe: Continued Values Collection/List/Dictionary Pin
Som Shekhar16-Dec-09 21:28
Som Shekhar16-Dec-09 21:28 
GeneralRe: Continued Values Collection/List/Dictionary Pin
Eddy Vluggen16-Dec-09 21:34
professionalEddy Vluggen16-Dec-09 21:34 
GeneralRe: Continued Values Collection/List/Dictionary Pin
Som Shekhar16-Dec-09 21:39
Som Shekhar16-Dec-09 21:39 
GeneralRe: Continued Values Collection/List/Dictionary Pin
Eddy Vluggen16-Dec-09 21:53
professionalEddy Vluggen16-Dec-09 21:53 
GeneralRe: Continued Values Collection/List/Dictionary Pin
Som Shekhar16-Dec-09 21:56
Som Shekhar16-Dec-09 21:56 
GeneralRe: Continued Values Collection/List/Dictionary Pin
Eddy Vluggen17-Dec-09 1:53
professionalEddy Vluggen17-Dec-09 1:53 
GeneralRe: Continued Values Collection/List/Dictionary Pin
Som Shekhar17-Dec-09 2:40
Som Shekhar17-Dec-09 2:40 
GeneralRe: Continued Values Collection/List/Dictionary Pin
Eddy Vluggen17-Dec-09 9:34
professionalEddy Vluggen17-Dec-09 9:34 
GeneralRe: Continued Values Collection/List/Dictionary Pin
Som Shekhar17-Dec-09 10:12
Som Shekhar17-Dec-09 10:12 
GeneralRe: Continued Values Collection/List/Dictionary Pin
Eddy Vluggen17-Dec-09 13:13
professionalEddy Vluggen17-Dec-09 13:13 
GeneralRe: Continued Values Collection/List/Dictionary Pin
Som Shekhar18-Dec-09 18:59
Som Shekhar18-Dec-09 18:59 
GeneralRe: Continued Values Collection/List/Dictionary Pin
Eddy Vluggen19-Dec-09 0:48
professionalEddy Vluggen19-Dec-09 0:48 

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.