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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:48:29+00:00 2026-06-13T09:48:29+00:00

we had a programing lesson today. Very easy exercise in console. I wrote a

  • 0

we had a programing lesson today. Very easy exercise in console. I wrote a loop to load from console char by char by getchar() with assignment, all of these in loop term.

char c;
while((c = getchar()) != '\n'){
...

Someone says, that this isn’t safe to use, others says, that in C/C++ I can do this, but not in C#.

I tried this

string s;
if((s = Console.ReadLine()) != ""){
...

But this also works, so I don’t understand why this is unsafe. Or isn’t it?

Edit:\ I also read this Why would you use an assignment in a condition? but this isn’t answer to my question at all.

  • 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-13T09:48:30+00:00Added an answer on June 13, 2026 at 9:48 am

    The main operation in your sample is != which is not an assignment.
    What you can not do in C# (And I think it was the right design decision) is something like this:

    if (s = "")
    ...
    

    The problem here is that it is very similar to the usual equals operator ==. There are cases when this code is intentional, but usually it is a typo which is very difficult to find. Compare it with this:

    if (s == "")
    ...
    

    When you are looking for a bug in your code, you can easily overlook this.

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

Sidebar

Related Questions

I'm working on my first programming assignment for Java and I had another question.
I had to comment out the line below (example is from http://en.wikibooks.org/wiki/Clojure_Programming/Examples/Lazy_Fibonacci ) (def
The following code is not entering the i for loop. I have had problems
Before I have started to do web-programming I had thought it was easy. Now,
I am new to programming but had some spare time and just got a
I am currently doing some network programming and had a couple questions concerning timeouts.
In an programming interview I had yesterday, one of the programs I had to
So for my programming class we have had a project to create a virtual
Has someone here ever had experience with the D programming language ? It seems
I am new to C# Programming. I had drag a login control into my

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.