System.Collections.Queue.ToArray C# (CSharp) Method

ToArray() public method

public ToArray ( ) : Object[]
return Object[]
        public virtual Object[] ToArray()
        {
            if (_size == 0)
                return Array.Empty<Object>();

            Object[] arr = new Object[_size];
            if (_head < _tail)
            {
                Array.Copy(_array, _head, arr, 0, _size);
            }
            else
            {
                Array.Copy(_array, _head, arr, 0, _array.Length - _head);
                Array.Copy(_array, 0, arr, _array.Length - _head, _tail);
            }

            return arr;
        }

Same methods

Queue::ToArray ( ) : object[]

Usage Example

        private CodeElement FindType(ProjectItems projectItems, string typename)
        {
            var tokens = typename.Split('.');
            var path =new Queue<string>(tokens.ToList());
         

            while ( path.Count>0)
            {
                var itemName = path.Dequeue();
                var  found = false;
                Debug.WriteLine("Searching for " + itemName );
                if (projectItems == null) break;

                foreach (ProjectItem projectItem in projectItems)
                {
                    Debug.WriteLine("Checking " + projectItem.Name );
                    if (projectItem.Name.Equals(itemName, StringComparison.CurrentCultureIgnoreCase))
                    {
                        Debug.WriteLine("Found the project Item!!!");
                        found = true;

                        if (projectItem.ProjectItems != null && projectItem.ProjectItems.Count > 0)
                        {
                            Debug.WriteLine("Searching children");
                            // search the children of this projectitem
                            var foundHere = FindType(projectItem.ProjectItems, string.Join(".", path.ToArray()));

                            if (foundHere != null)
                            {
                                Debug.WriteLine("Found in children of " + projectItem.Name );

                                return foundHere;
                            }
                            Debug.WriteLine("Continuing looking");
                            
                            break;
                        }
                    }
                    else
                    {
                       var theType = FindType(projectItem, typename);

                        if (theType != null)
                        {
                            Debug.WriteLine("Found it!!!!" + theType.FullName );
                            return theType;
                        }
                    }
                    
                }
                if (!found)
                {
                    Debug.WriteLine("Didnt find this token" + itemName );
                    break;
                }
            }
            return null;
        }
All Usage Examples Of System.Collections.Queue::ToArray