Skip to content

Constructors in inheritance

Orlando Salcido

Asked May 3, 2007, 2:59 PM EDT2 answers
Share
LinkedInX
I have class CReader that inherits StreamReader. When i try to assign Stream via [code] CReader(NetworkStream.GetStream()); [/code] I get 'No overload for CReader takes 1 arguments' This works if I use it in plain old StreamReader instead of CReader. I guess I need a custom constructor.... but how??

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Mike Gold
    0
    The following should work:

    TypeScript
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Text;
    namespace CustomStreamReader
    {
      class CustomStreamReader : StreamReader
       {
          public CustomStreamReader(Stream fs) : base(fs)
            {
            }
        }
    }


    And you should call it as follows:

    CustomStreamReader cr = new CustomStreamReader(NetworkStream.GetStream());

    0
  • 0
    ahh works great thank you Mike!
    0