Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. C# bool datatype horror [modified]

C# bool datatype horror [modified]

Scheduled Pinned Locked Moved The Weird and The Wonderful
csharplearning
9 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Shyam Bharath
    wrote on last edited by
    #1

    Here is a code i came across in my own project. Apparently I coded this when I was learning C# few years back. It gave me a good laugh now

    bool isActive;
    if (chkExamActive.Checked == false)
    isActive = false;
    else
    isActive = true;

    EDIT OK I was just going through this old project of mine so here is another one in the same .cs file

    ArrayList correctAnswers = new ArrayList();
    correctAnswers.Add(txtPhrase.Text);

    QuestionTableAdapter questionAdapter = new QuestionTableAdapter();
    long QuestionID = questionAdapter.GetData()[0].QuestionID;
    CorrectAnswerTableAdapter correctAnswerAdapter = new CorrectAnswerTableAdapter();
    foreach (string correctAnswer in correctAnswers)
    correctAnswerAdapter.Insert(correctAnswer, QuestionID);

    Find the horror above :rolleyes:

    ------------------------------------------- It's code that drives you - Shyam

    modified on Monday, November 24, 2008 11:26 AM

    P J L O 4 Replies Last reply
    0
    • S Shyam Bharath

      Here is a code i came across in my own project. Apparently I coded this when I was learning C# few years back. It gave me a good laugh now

      bool isActive;
      if (chkExamActive.Checked == false)
      isActive = false;
      else
      isActive = true;

      EDIT OK I was just going through this old project of mine so here is another one in the same .cs file

      ArrayList correctAnswers = new ArrayList();
      correctAnswers.Add(txtPhrase.Text);

      QuestionTableAdapter questionAdapter = new QuestionTableAdapter();
      long QuestionID = questionAdapter.GetData()[0].QuestionID;
      CorrectAnswerTableAdapter correctAnswerAdapter = new CorrectAnswerTableAdapter();
      foreach (string correctAnswer in correctAnswers)
      correctAnswerAdapter.Insert(correctAnswer, QuestionID);

      Find the horror above :rolleyes:

      ------------------------------------------- It's code that drives you - Shyam

      modified on Monday, November 24, 2008 11:26 AM

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      That sort of thing has been posted so often it has lost its horror. :-D

      S 1 Reply Last reply
      0
      • P PIEBALDconsult

        That sort of thing has been posted so often it has lost its horror. :-D

        S Offline
        S Offline
        Shyam Bharath
        wrote on last edited by
        #3

        Yeah even I saw this horror too many times here, so I expected this to have lost its horror... I edited the post with one more horror I found. Hope this horror is not so common :rolleyes:

        ------------------------------------------- It's code that drives you - Shyam

        1 Reply Last reply
        0
        • S Shyam Bharath

          Here is a code i came across in my own project. Apparently I coded this when I was learning C# few years back. It gave me a good laugh now

          bool isActive;
          if (chkExamActive.Checked == false)
          isActive = false;
          else
          isActive = true;

          EDIT OK I was just going through this old project of mine so here is another one in the same .cs file

          ArrayList correctAnswers = new ArrayList();
          correctAnswers.Add(txtPhrase.Text);

          QuestionTableAdapter questionAdapter = new QuestionTableAdapter();
          long QuestionID = questionAdapter.GetData()[0].QuestionID;
          CorrectAnswerTableAdapter correctAnswerAdapter = new CorrectAnswerTableAdapter();
          foreach (string correctAnswer in correctAnswers)
          correctAnswerAdapter.Insert(correctAnswer, QuestionID);

          Find the horror above :rolleyes:

          ------------------------------------------- It's code that drives you - Shyam

          modified on Monday, November 24, 2008 11:26 AM

          J Offline
          J Offline
          Jason Lepack LeppyR64
          wrote on last edited by
          #4

          bool isActive = chkExamActive.Checked; This would cause issue if the checkbox were IsThreeState, because it has a third state, indetermintate. The code above could therefore give isActive a null value, therefore possibly causing issues later. However, the code you posted is still crap. :D

          S 1 Reply Last reply
          0
          • J Jason Lepack LeppyR64

            bool isActive = chkExamActive.Checked; This would cause issue if the checkbox were IsThreeState, because it has a third state, indetermintate. The code above could therefore give isActive a null value, therefore possibly causing issues later. However, the code you posted is still crap. :D

            S Offline
            S Offline
            Shyam Bharath
            wrote on last edited by
            #5

            My mistake for not mentioning it... This is code behind for ASP.net page so I guess IsThreeState situation wouldn't make my code great ;P

            ------------------------------------------- It's code that drives you - Shyam

            1 Reply Last reply
            0
            • S Shyam Bharath

              Here is a code i came across in my own project. Apparently I coded this when I was learning C# few years back. It gave me a good laugh now

              bool isActive;
              if (chkExamActive.Checked == false)
              isActive = false;
              else
              isActive = true;

              EDIT OK I was just going through this old project of mine so here is another one in the same .cs file

              ArrayList correctAnswers = new ArrayList();
              correctAnswers.Add(txtPhrase.Text);

              QuestionTableAdapter questionAdapter = new QuestionTableAdapter();
              long QuestionID = questionAdapter.GetData()[0].QuestionID;
              CorrectAnswerTableAdapter correctAnswerAdapter = new CorrectAnswerTableAdapter();
              foreach (string correctAnswer in correctAnswers)
              correctAnswerAdapter.Insert(correctAnswer, QuestionID);

              Find the horror above :rolleyes:

              ------------------------------------------- It's code that drives you - Shyam

              modified on Monday, November 24, 2008 11:26 AM

              L Offline
              L Offline
              Lutoslaw
              wrote on last edited by
              #6

              Shyam Bharath wrote:

              ArrayList correctAnswers = new ArrayList();
              correctAnswers.Add(txtPhrase.Text);

              QuestionTableAdapter questionAdapter = new QuestionTableAdapter();
              long QuestionID = questionAdapter.GetData()[0].QuestionID;
              CorrectAnswerTableAdapter correctAnswerAdapter = new CorrectAnswerTableAdapter();
              foreach (string correctAnswer in correctAnswers)
              correctAnswerAdapter.Insert(correctAnswer, QuestionID);

              a few guesses at first glance: 0. no txtPhrase validation 1. questionAdapter will be empty since it is just only constructed (failure) -OR- it has a default, random (?) data entry or a static ID field acquiarable only by an instance method (horror). 2. [supposition:] question data is queried on each method call just to get an ID instead storing it somewhere. 3. correctAnswers contains just one element and so foreach loop is redutant. are some of them correct?

              Greetings - Gajatko Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.

              S 1 Reply Last reply
              0
              • L Lutoslaw

                Shyam Bharath wrote:

                ArrayList correctAnswers = new ArrayList();
                correctAnswers.Add(txtPhrase.Text);

                QuestionTableAdapter questionAdapter = new QuestionTableAdapter();
                long QuestionID = questionAdapter.GetData()[0].QuestionID;
                CorrectAnswerTableAdapter correctAnswerAdapter = new CorrectAnswerTableAdapter();
                foreach (string correctAnswer in correctAnswers)
                correctAnswerAdapter.Insert(correctAnswer, QuestionID);

                a few guesses at first glance: 0. no txtPhrase validation 1. questionAdapter will be empty since it is just only constructed (failure) -OR- it has a default, random (?) data entry or a static ID field acquiarable only by an instance method (horror). 2. [supposition:] question data is queried on each method call just to get an ID instead storing it somewhere. 3. correctAnswers contains just one element and so foreach loop is redutant. are some of them correct?

                Greetings - Gajatko Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.

                S Offline
                S Offline
                Shyam Bharath
                wrote on last edited by
                #7

                gajatko wrote:

                are some of them correct?

                Cool. You got the third one correct. Let me explain others

                gajatko wrote:

                1. questionAdapter will be empty since it is just only constructed (failure) -OR- it has a default, random (?) data entry or a static ID field acquiarable only by an instance method (horror).

                The adapter was generated by xsd tool and it fills data in the next line when I call GetData() method. For point 2, good supposition :) . Luckily I didn't do that horror

                gajatko wrote:

                0. no txtPhrase validation

                I have put validation controls in ASP.net WebForm. I guess that should be enough Cool that you were able to identify the for loop one. You get my 5 :)

                ------------------------------------------- It's code that drives you - Shyam

                1 Reply Last reply
                0
                • S Shyam Bharath

                  Here is a code i came across in my own project. Apparently I coded this when I was learning C# few years back. It gave me a good laugh now

                  bool isActive;
                  if (chkExamActive.Checked == false)
                  isActive = false;
                  else
                  isActive = true;

                  EDIT OK I was just going through this old project of mine so here is another one in the same .cs file

                  ArrayList correctAnswers = new ArrayList();
                  correctAnswers.Add(txtPhrase.Text);

                  QuestionTableAdapter questionAdapter = new QuestionTableAdapter();
                  long QuestionID = questionAdapter.GetData()[0].QuestionID;
                  CorrectAnswerTableAdapter correctAnswerAdapter = new CorrectAnswerTableAdapter();
                  foreach (string correctAnswer in correctAnswers)
                  correctAnswerAdapter.Insert(correctAnswer, QuestionID);

                  Find the horror above :rolleyes:

                  ------------------------------------------- It's code that drives you - Shyam

                  modified on Monday, November 24, 2008 11:26 AM

                  O Offline
                  O Offline
                  ocdogan
                  wrote on last edited by
                  #8

                  idiotic code. :laugh:

                  T 1 Reply Last reply
                  0
                  • O ocdogan

                    idiotic code. :laugh:

                    T Offline
                    T Offline
                    TJS4u
                    wrote on last edited by
                    #9

                    u r a champion to judge others?????/

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups