Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 920153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:39:52+00:00 2026-05-15T18:39:52+00:00

I have a problem. When I run my program, it comes up with an

  • 0

I have a problem. When I run my program, it comes up with an error, specifically the CS1023 error. I guess it’s because I have a declaration inside a statement, but I don’t know how else to write the code. Sometimes C# annoys me, because in C++ I could get away with similar things… anyway, here’s the code. I would appreciate it if somebody could explain it to me.
Error Message Link

void BtnTotalSeasonsClick(object sender, EventArgs e)
{
    using (var stream = new FileStream(drvFile, FileMode.Open, FileAccess.ReadWrite)) 
    Byte[] bytes = System.Text.ASCIIEncoding.GetBytes(txtTotalSeasons.Text);
    {
        stream.Position = 4;
        Stream.WriteByte(0xCD);
    }
}

Fixed Code with CS0120 error.

        {
using (var stream = new FileStream(drvFile, FileMode.Open, FileAccess.ReadWrite))  
{ 
Byte[] bytes = System.Text.ASCIIEncoding.GetBytes(txtTotalSeasons.Text); 
stream.Position = 4; 
Stream.WriteByte(0xCD); 
} 
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T18:39:53+00:00Added an answer on May 15, 2026 at 6:39 pm

    There’s nothing apparently wrong with the code you pasted in. Perhaps the error is somewhere else above this, and the compiler is getting confused?

    Ah, I see you’ve changed the code.

    The problem here is you are declaring the Byte[] array outside the intended using block. Since the scope of the declaration as is is only one line, this constitutes a logic error, and the compiler catches it with a compile-time error.

    The compiler is interpreting your code like this:

    using (var stream = new FileStream(drvFile, FileMode.Open, FileAccess.ReadWrite))  
    { 
        Byte[] bytes = System.Text.ASCIIEncoding.GetBytes(txtTotalSeasons.Text); 
    }
    
    {        
        stream.Position = 4; 
        stream.WriteByte(0xCD); 
    }
    

    To fix it, move the Byte[] inside the braces, or outside the using block:

    using (var stream = new FileStream(drvFile, FileMode.Open, FileAccess.ReadWrite))  
    { 
        Byte[] bytes = System.Text.ASCIIEncoding.GetBytes(txtTotalSeasons.Text); 
        stream.Position = 4; 
        stream.WriteByte(0xCD); 
    } 
    

    -or-

    Byte[] bytes = System.Text.ASCIIEncoding.GetBytes(txtTotalSeasons.Text); 
    
    using (var stream = new FileStream(drvFile, FileMode.Open, FileAccess.ReadWrite))  
    { 
        stream.Position = 4; 
        stream.WriteByte(0xCD); 
    } 
    

    Personally, I like being annoyed by the compiler here, since it saves me from a run-time error.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 500k
  • Answers 500k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer IDEA will understand parallel JUnit tests only since version 10.… May 16, 2026 at 2:05 pm
  • Editorial Team
    Editorial Team added an answer Found it! Here is the proof: As you can see,… May 16, 2026 at 2:05 pm
  • Editorial Team
    Editorial Team added an answer serialize and unserialize are pretty watertight functions with one notorious… May 16, 2026 at 2:05 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I seem to have a problem, I have a growing business to run but
When I run an executable that I built, I get the following error: The
I am new to assembly language. I have written a program for taking an
I have followed all the instructions here: http://www.tonyspencer.com/2003/10/22/curl-with-php-and-apache-on-windows/ to install & config apache get
It seems I tend to attract strange issues. This time, I have written a
I have a WinForms app built using Visual Studio 2005, including the crystal reports
When publishing my web application and then running it will return the error Could
I have a .NET application that makes calls to a native Win32 DLL using
Got an annoying problem here. I've got an NHibernate/Forms application I'm working through SVN.
I am trying to figure out the memory consumption by my (C++) program using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.