Returning Multiple Values for the "To Do List Contract" Example
In this post i learned how to add items to a fixed array.
on this post i extended this contract by making use of a flexible array size.
in both posts, i was only returning the task and no the priority. In this post i will be returning multiple values
on this post i extended this contract by making use of a flexible array size.
in both posts, i was only returning the task and no the priority. In this post i will be returning multiple values
pragma solidity ^0.4.0;
contract ToDoAreshFlexible{
//Declare a struct similar to C++ holding details of a single ToDo Item
struct Item{
string task;
uint priority;
}
//An Array of structs similar to C++ (flexible storage) and index start at 0
Item[] ToDoList;
//this is a constructor, notice it has the same name as the Contract name
function ToDoAreshFlexible() public {
}
//Adds an item to the list using PUSH
function AddToDo(string _task, uint _priority) public
{
ToDoList.push(Item(_task,_priority));
}
//returns a single item given an index since it requires more gas to iterate thru
//returning multiple Items, both task and priority with a single call
function getToDoList(uint _index) public returns(string, uint ){
return (ToDoList[_index].task, ToDoList[_index].priority);
}
}
Comments
Post a Comment