C# bool datatype horror [modified]
-
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
-
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
That sort of thing has been posted so often it has lost its horror. :-D
-
That sort of thing has been posted so often it has lost its horror. :-D
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
-
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
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 -
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. :DMy 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
-
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
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.
-
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.
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
-
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