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 6015269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:48:42+00:00 2026-05-23T02:48:42+00:00

I am just getting started with Code Contracts, and need a little help in

  • 0

I am just getting started with Code Contracts, and need a little help in correcting an error:

Given this code:

class MyClass
{
    private bool _isUsed = false;

    public void SomeMethod()
    {
        Contract.Requires(!_isUsed);
    }
}

I get the following error:

error CC1038: Member 'MyClass._isUsed' has less visibility than the enclosing method 'MyClass.SomeMethod'

which seems to makes alot of the standard checks unavailable. What am I missing in this example?

  • 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-23T02:48:43+00:00Added an answer on May 23, 2026 at 2:48 am

    You have a public method SomeMethod. However, you’re requiring that a private member variable is set to false. You provide no way of setting _isUsed, and so you’re putting a check on a variable that a caller has no control over.

    You could make _isUsed into a property i.e.

    public bool IsUsed {get; set;}
    

    And then in your SomeMethod() have

    Contract.Requires(!IsUsed);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am just getting started with expression trees so I hope this makes sense.
I'm just getting started in F# and have a basic question. Here's the code:
I am just getting started with IoC containers so apologies if this is a
Just getting started with Linq to SQL so forgive the newbie question. I'm trying
Just getting started using MVC in ASP.NET, I'm going to have it so users
I am just getting started with flex and am using the SDK (not Flex
I'm just getting started with learning about Unit testing (and TDD in general). My
I'm just getting started with Custom User Controls in C# and I'm wondering if
I'm just getting started working with foreign keys for the first time and I'm
I am just getting started with MVC, and it seems like it will be

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.