File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -67,8 +67,25 @@ public FixedSizeQueue(int size, IEnumerable<T> data)
6767 throw new ArgumentException ( $ "The max size set for the queue is { size } , but got { dataCount } initial values.") ;
6868#endif
6969
70+ if ( data is ICollection < T > collection )
71+ {
72+ if ( collection . Count > size )
73+ throw new ArgumentException ( $ "The max size set for the queue is { size } , but got { collection . Count } initial values.") ;
74+
75+ foreach ( var item in collection )
76+ Enqueue ( item ) ;
77+ return ;
78+ }
79+
80+ var index = 0 ;
7081 foreach ( var item in data )
82+ {
83+ if ( index >= size )
84+ throw new ArgumentException ( $ "The max size set for the queue is { size } , but got { index + 1 } initial values.") ;
85+
7186 Enqueue ( item ) ;
87+ index ++ ;
88+ }
7289 }
7390
7491 /// <summary>
You can’t perform that action at this time.
0 commit comments