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

  • Home
  • SEARCH
  • 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 9022941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:38:24+00:00 2026-06-16T05:38:24+00:00

I am having a hell of a time getting a variable from the function

  • 0

I am having a hell of a time getting a variable from the function of another class usable in my Game1 (main) class. Specifically, I want to take width and height from the function SaveData in SetWindowSize.cs and use it in ReadSettings in Game1.cs.

I get the error

‘ShovelShovel.SetWindowSize’ does not contain a definition for
‘height’. Same for ‘width’.

Game1.cs (the function only)

protected void ReadSettings()
{
    try
    {
        if (File.Exists(SetWindowSize.savePath))
        {
            using (FileStream fileStream = new FileStream(SetWindowSize.savePath,
                                                          FileMode.Open))
            {
                using (BinaryReader binaryReader = new BinaryReader(fileStream))
                {
                    SetWindowSize.width = binaryReader.ReadInt32();
                    SetWindowSize.height = binaryReader.ReadInt32();
                }
            }
        }
    }
    catch
    {
    }
}

SetWindowSize.cs

namespace ShovelShovel
{
            protected void ReadSettings()
    {
        try
        {
            if (File.Exists(savePath))
            {
                using (FileStream fileStream = new FileStream(savePath, FileMode.Open))
                {
                    using (BinaryReader binaryReader = new BinaryReader(fileStream))
                    {
                        var windowSize = WindowSizeStorage.ReadSettings();

                        WindowSize.Width = windowSize.Width;
                        WindowSize.Height = windowSize.Height;
                    }
                }
            }
        }
        catch
        {
        }
    }

Thank you so much to anyone and everyone that can help me, I really appreciate it.

  • 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-06-16T05:38:26+00:00Added an answer on June 16, 2026 at 5:38 am

    This might do the trick:

    public class WindowSize
    {
        public int Width { get; set; }
        public int Height { get; set; }
    }
    
    public static class WindowSizeStorage
    {
        public static string savePath = "WindowSize.dat";
    
        public static WindowSize ReadSettings()
        {   
            var result = new WindowSize();
            using (FileStream fileStream = new FileStream(SetWindowSize.savePath, FileMode.Open))
            {
                using (BinaryReader binaryReader = new BinaryReader(fileStream))
                {
                    result.Width = binaryReader.ReadInt32();
                    result.Height = binaryReader.ReadInt32();
                }
            }
    
            return result;
        }
    
        public static void WriteSettings(WindowSize toSave)
        {
            using (BinaryWriter binaryWriter = new BinaryWriter(File.Open(savePath, FileMode.Create)))
            {
                binaryWriter.Write(toSave.Width);
                binaryWriter.Write(toSave.Height);
            }
        }
    }
    

    Usage:

    // Read
    var windowSize = WindowSizeStorage.ReadSettings();
    
    myForm.Width = windowSize.Width;
    myForm.Height = windowSize.Height;
    
    // Write
    var windowSize = new WindowSize { Width = myForm.Width, Height = myForm.Height };
    
    WindowSizeStorage.WriteSettings(windowSize);
    

    Please note that writing an answer like this (presenting all code) is not the common way; I just felt like it. I tried to show some object-oriented design principles, where each class does its own thing.

    If you want to transfer compicated objects between methods (i.e. more than one primitive type), you will usually create a Data Transfer Object (DTO) like WindowSize.

    The WindowSizeStorage class has the sole responsibility to store and retreive such a WindowSize object. From your code you simply tell the storage to store or retreive the settings you wish.

    But as I get from your question and comments, you haven’t got much experience using C# or perhaps any programming experience at all. Try to pick up on a tutorial or two so you can understand how to put your thoughts into code.

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

Sidebar

Related Questions

I'm having a hell of a time getting WCF Data Services to work within
I am having a hell of a time getting a MovieClip to detect whether
I've been having a hell of a time getting Eclipse to debug my CakePHP
I am having a hell of a time getting my extension up on Magento
I'm having a hell of a time getting this to cooperate. Basically I'm trying
I am having one hell of a time coming up with a decent way
I'm having a hell of a time finding documentation which clearly explains how to
I'm having one hell of a time trying to get my databinding to work
I'm having a hell of a time trying to get (what I thought was)
Well I'm having a hell of a time trying to get my CPU down

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.