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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:44:01+00:00 2026-06-04T02:44:01+00:00

I found this other stack overflow question about files and directories , and the

  • 0

I found this other stack overflow question about files and directories, and the answer included this statement:

bool isDir = (File.GetAttributes(path) & FileAttributes.Directory)
             == FileAttributes.Directory;

His question was about .net, and I was coding in C# .net in Visual Studio. Is the ability to have both an assignment operator and an equals operator in the same statement work for all .net languages or is it specific to certain ones? Also, can I get an explanation for how the above code works? Assuming that path refers to a directory, I’d expect isDir to be true, but can anyone explain why?

  • 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-04T02:44:03+00:00Added an answer on June 4, 2026 at 2:44 am

    The equality test performed by the == operator takes precedence over the assignment performed by the = operator. Therefore, the isDir variable will be set equal to true if the two sides of the == operator are equal, otherwise it will be set to false. In other words, it’s the equivalent of saying:

    if ((File.GetAttributes(path) & FileAttributes.Directory) == FileAttributes.Directory)
        isDir = true;
    else
        isDir = false;
    

    This is possible in VB.NET. I cannot answer for other languages. In VB.NET, the equivalent would be:

    Dim isDir As Boolean = ((File.GetAttributes(path) And FileAttributes.Directory) = FileAttributes.Directory)
    

    Since VB uses the same character (=) for both it’s assignment and equality-test operators, it determines which operation you are performing based on context. The VB compiler is smart enough to know that the first = operator is an assignment and the second one is an equality test. However, this is obviously confusing, so it is often discouraged, for readability sake. It’s particularly confusing to people with backgrounds in other languages. For instance, in C#, you could do the following to set two variables to the same value:

    int y;
    int x = y = 5;  // Both x and y will be set to 5
    

    The reason that happens in C# is because = is always an assignment operator, and the assignment expression always evaluates to (returns) the value that was assigned. Therefore, in this case, the expression y = 5 not only assigns the value 5 to the variable y, but it also evaluates to the value of 5 as well. So, when you set x to the value of that expression, it gets set to 5 as well. In VB, however, the result is very different:

    Dim y As Integer
    Dim x As Integer = y = 5
    

    In VB, the compiler will assume that the expression y = 5 is an equality test, so it will evaluate to False. Therefore, it will attempt to set x = False which may or may not work depending on the value of Option Strict.

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

Sidebar

Related Questions

I found some other questions about this, but they didn't work for me :(
I've found no other stackexchange site to ask this question so I present it
This question gets asked a lot, but I still haven't found a straight answer
There are other questions about this but I didn't find a clear answer. With
I've found plenty of other topics similar to this one, but I they are
This topic can look similar to others but I haven't found any usable answer
Found this question that explained a way to communicate between layers. However there is
Sorry for the probably stupid question. Since I found nothing about it on the
My question is very similar to a number of others I've found on Stack
I haven't found a concrete answer as to whether this is possible, but it

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.