Advertisement
Hiteshw11

Swapping Values Using Generic Function

Nov 28th, 2024
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.35 KB | Source Code | 0 0
  1. void main() {
  2.   var a = One();
  3.   List<int> list1=(a.swapValues<int>(5,4));
  4.   print("After swapping values value of a is ${list1[0]} and value of b is ${list1[1]}");
  5. }
  6.  
  7.  
  8. class One
  9. {
  10. One();
  11.  
  12. List<T> swapValues<T>(T a, T b)
  13. {
  14.  
  15. print("The value before swapping of a is $a and value of b is $b");
  16.  
  17. T temp =a;
  18. a=b;
  19. b=temp;
  20.  
  21. return [a,b];
  22. }
  23.  
  24. }
Tags: dart
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement