-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBT-2.sol
36 lines (28 loc) · 928 Bytes
/
BT-2.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//SPDX-License-Identifier:UNLICENSED
pragma solidity ^0.8.0;
contract Student_1{
struct Student{
uint16 id;
string name;
}
Student[] public studentData;
function addStudent(string memory name,uint16 id) public{
for(uint8 i=0;i<studentData.length;i++){
if(studentData[i].id == id){
revert("id already exists");
}
}
studentData.push(Student(id,name));
}
function getAll() public view returns (Student[] memory){
require(studentData.length > 0,"studentdata is empty");
return studentData;
}
function getLength() public view returns (uint256){
return studentData.length;
}
function getIndex(uint16 idx) public view returns (Student memory){
require(idx < studentData.length,"index out of bound");
return studentData[idx];
}
}