new Student() { StudentID = 1, StudentName = "John", Age = 18 } ,
new Student() { StudentID = 2, StudentName = "Steve", Age = 21 } ,
new Student() { StudentID = 3, StudentName = "Bill", Age = 18 } ,
new Student() { StudentID = 4, StudentName = "Ram" , Age = 20 } ,
new Student() { StudentID = 5, StudentName = "Abram" , Age = 21 }
```i found this code for some tutorial website and I need to store this list of value in dictionary
like student id would be key and student name and age would be value and if want to access I need to implement linq query can anyone help me I really appreciate
my question is basically
1-how can I store multiple value in dictionary and what is way to access that
Hi @Aleem_Khan
You can decalred the dictionary of key I’d of type int32 and value as list
can you please help me with any example file Nived really appreciate
Hi @Aleem_Khan
You can try this
First create an dictionary let’s say dict_1 with datatype as follow
Key : int32
Value : List
Now intialise the dictionary as below
dict_1= New Dictionary (Of Int32,List(Of Object))
Then u can add the key and item to it
Regards
Nived N
Happy Automation
I did the same but I need your few more help how could I add value while initialize the dictionary
New Dictionary (Of Int32,List(Of Object)){ StudentID = 2, StudentName = “Steve”, Age = 21 }
like this please help
U can assign activitiy for this
@Aleem_Khan Check the below Expression :
myDict = new Dictionary(Of Integer,String()) From {{1,{"2","Steve","21"}},{2,{"3","Tony","23"}}}
The Above is the Initialisation when the value of the Dictionary is of the Type String Array.
If you need the Value as List Type, You can use the Below Expression (A Bit Lengthy):
new Dictionary(Of Integer,List(Of Object)) From {{1,new List(Of Object)({"2","Steve","21"})},{2,new List(Of Object)({"3","Tony","23"})}}
You can use this in an Assign Activity in the same way.
Let us know if this isn’t the solution you needed.
thank you so much and how could i access these values
@Aleem_Khan Considering that myDict is the Dictionary variable, You can access the Values by using the Dictionary’s Keys in the same way. But Since the Value is a List or an Array, you would need to use the Method of Accessing the Values of a list by using the Indices.
Below Illustrations should help you:
myDict(1)(0).ToString //Accessing the The First Value of the List from the First Key of Dictionary - Outputs "2"
myDict(1)(1).ToString //Accessing the The Second Value of the List from the First Key of Dictionary - Outputs "Steve"
myDict(2)(1).ToString //Accessing the The Second Value of the List from the Second Key of Dictionary - Outputs "Tony"
Hope the above explanation is understandable. Let us know if you still need clarifications
lets assume following:
we do simulate the Student Class wit a Tuple (benefit is that we have type safety on the different fields instead of Object arrays , X:Object-Dictionaries, others…)
We keep all Students in a list or within a Dictionary.
Tuple creations:
A quick dictionary setup (showcasing using the exisiting and ne tuple creation)
Examples of accessing:
Retrieving Steven / retrieving age from Steve:
a sample LINQ: find all students which age is less then 21, return result as Tuple list:
For LINQ learning start start with Lists of Tuples, maybe it is easier on begin.
find starter help here:
LINQ_Learn_StudentExample.xaml (6.3 KB)
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.