System.IO.BinaryReader.ReadChars C# (CSharp) Méthode

ReadChars() public méthode

public ReadChars ( int count ) : char[]
count int
Résultat char[]
        public virtual char[] ReadChars(int count)
        {
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
            }
            if (_stream == null)
            {
                throw new ObjectDisposedException(null, SR.ObjectDisposed_FileClosed);
            }

            if (count == 0)
            {
                return Array.Empty<char>();
            }

            // SafeCritical: we own the chars buffer, and therefore can guarantee that the index and count are valid
            char[] chars = new char[count];
            int n = InternalReadChars(chars, 0, count);
            if (n != count)
            {
                char[] copy = new char[n];
                Buffer.BlockCopy(chars, 0, copy, 0, 2 * n); // sizeof(char)
                chars = copy;
            }

            return chars;
        }

Usage Example

Exemple #1
0
        /// <summary>
        /// Creates a new entity that was embedded next in the stream
        /// </summary>
        /// <param name="stream">The System.IO.BinaryReader to use.</param>
        public Entity(BinaryReader stream)
        {
            X = stream.ReadInt16();
            Y = stream.ReadInt16();
            Layer = stream.ReadInt16();
            Scripts = new List<string>();
            Type = (EntityType)stream.ReadInt16();
            stream.ReadBytes(8);

            short len;
            if (Type == EntityType.Person)
            {
                len = stream.ReadInt16();
                Name = new string(stream.ReadChars(len));
                len = stream.ReadInt16();
                Spriteset = new string(stream.ReadChars(len));
                int scripts = stream.ReadInt16();

                // read the person script data
                for (int i = 0; i < scripts; ++i)
                {
                    len = stream.ReadInt16();
                    Scripts.Add(new string(stream.ReadChars(len)));
                }

                stream.ReadBytes(16); // reserved
            }
            else
            {
                len = stream.ReadInt16();
                Function = new string(stream.ReadChars(len));
                Trigger = new CompiledMethod(Program._engine, Function);
            }
        }
All Usage Examples Of System.IO.BinaryReader::ReadChars