Пример #1
0
        static void Main()
        {
            // A collection of Documents
            Document[] docArray = new Document[2];

            // First entry is a Document
            docArray[0] = new Document("Test Document");

            // Second entry is a CompressibleDocument (ok because
            // CompressibleDocument is a Document)
            docArray[1] = new CompressibleDocument("Test compressibleDocument");


            // don't know what we'll pull out of this hat
            foreach (Document doc in docArray)
            {
                // report your name
                Console.WriteLine("Got: {0}", doc);

                // Both pass this test
                if (doc is IStorable)
                {
                    IStorable isDoc = (IStorable)doc;
                    isDoc.Read();
                }

                // fails for Document
                // passes for CompressibleDocument
                if (doc is ICompressible)
                {
                    ICompressible icDoc = (ICompressible)doc;
                    icDoc.Compress();
                }
            }
        }
Пример #2
0
        static void Main()
        {
            //kolekcija Docmunets
            Document[] docArray = new Document[2];

            //prvi unos je Document
            docArray[0] = new Document("Test document");

            //drugi unos je CompressibleDocument
            //uredu je jer je CompressibleDocument Document
            docArray[1] = new CompressibleDocument("Test compressible document");

            //ne znamo sta cemo izvuci iz sesira
            foreach (Document doc in docArray)
            {
                //ispisuje ime
                Console.WriteLine("Got: {0}", doc);

                //obje prolaze test
                //sa operatorom is
                if (doc is IStorable)
                {
                    IStorable isDoc = (IStorable)doc;
                    isDoc.Read();
                }

                //sa operatorom as
                IStorable isDoc2 = doc as IStorable;
                if (isDoc2 != null)
                {
                    isDoc2.Read();
                }

                //ne uspjeva za Documnet
                //prolazi za CompressibleDocument
                if (doc is ICompressible)
                {
                    ICompressible icDoc = (ICompressible)doc;
                    icDoc.Compress();
                }
            }
        }
Пример #3
0
        static void Main()
        {
            // 一组Document
            Document[] docArray = new Document[2];

            docArray[0] = new Document("Test Document");

            docArray[1] = new CompressibleDocument("Test compressibleDocument");

            foreach (Document doc in docArray)
            {
                Console.WriteLine("Got: {0}", doc);

                // if (doc is IStorable)
                // {
                //     IStorable isDoc = (IStorable)doc;
                //     isDoc.Read();
                // }

                // if (doc is ICompressible)
                // {
                //     ICompressible icDoc = (ICompressible)doc;
                //     icDoc.Compress();
                // }

                IStorable isDoc = doc as IStorable;
                if (isDoc != null)
                {
                    isDoc.Read();
                }

                IComparable isDoc = doc as ICompressible;
                if (icDoc != null)
                {
                    icDoc.Compress();
                }
            }
        }