0

My code:

public class UplaodedFile
{
    public UploadedFile File = null;
    public string Description = null;
    public string OriginalFileName = null;
    public byte[] inputStream ; 

    public UplaodedFile(UploadedFile file, string desc, string FileName, byte[] inputStream)
    {
        File = file;
        Description = desc;
        OriginalFileName = FileName;
        inputStream = inputStream;
    }
} 

I am creating an object as below:

UplaodedFile uploadedfile = new UplaodedFile(uploaded_file, description, originalFileName, file_contents);

and when I try to access the uploadedfile.inputStream, I am getting null.

What am I doing wrong?

1
  • Rename your field to InputStream which should be done anyway because it's public. But you should not have public fields, instead use properties. Read why properties matter Commented Jul 12, 2017 at 9:59

2 Answers 2

1

You are referring to constructor's argument in constructor

Instead of

inputStream = inputStream;

You need to write

this.inputStream = inputStream;
Sign up to request clarification or add additional context in comments.

Comments

0

By setting

inputStream = inputStream;

you only assign to the parameter inputStream. As your class field is also named inputStream you need to tell the compiler to set it by using this:

this.inputStream = inputStream;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.