Click here to Skip to main content
16,016,477 members
Home / Discussions / C#
   

C#

 
GeneralMessage Removed Pin
10-Feb-18 9:59
mveRichard MacCutchan10-Feb-18 9:59 
AnswerMessage Removed Pin
10-Feb-18 11:28
Markhoernchen10-Feb-18 11:28 
QuestionError with Primary key in Sql database Pin
Member 1367168610-Feb-18 7:32
Member 1367168610-Feb-18 7:32 
AnswerRe: Error with Primary key in Sql database Pin
Wendelius10-Feb-18 8:27
mentorWendelius10-Feb-18 8:27 
QuestionSplit a String of numbers in textfield Pin
auting829-Feb-18 11:06
auting829-Feb-18 11:06 
AnswerRe: Split a String of numbers in textfield Pin
Luc Pattyn9-Feb-18 16:22
sitebuilderLuc Pattyn9-Feb-18 16:22 
GeneralRe: Split a String of numbers in textfield Pin
auting8210-Feb-18 8:03
auting8210-Feb-18 8:03 
GeneralRe: Split a String of numbers in textfield Pin
Luc Pattyn10-Feb-18 8:41
sitebuilderLuc Pattyn10-Feb-18 8:41 
Hi,

I have lots of comments, here are just a few:

1. I don't think Sensor.GetAnalogValue() is doing what you think it is doing, I fail to see how the current code could be useful. Maybe you should first add a comment explaining what the method is supposed to do, and only then compare the code with the written description.

2. I see two new Random() statements inside Sensor. They tell me you did not understand the matter that was handled in your earlier thread, two days ago.

This is what the Random class does:
- each NextValue() returns a value assumed to be random, however it is never random, it is pseudo-random, which means anyone knowing the internal code can predict the next value. The values returned are from a huge but fixed and circular list (not stored but calculated), and the only random thing about it is you can influence where in the list the sequence will start, that is what the "seed" does.
- If you provide the same seed to different Random instances, you get the same values returned.
- And if you don't, the .NET Random class will derive a seed from the current time with millisecond resolution. As creating a Random object takes much less than a millisecond, two consecutive new Random() will typically use the same seed.

Normally, the easy way to correctly use Random is by having only one of them, so make it a static field within your Sensor class.

3. If you already know what Properties are, you shouldn't have a method called GetSensId(). If properties still are in your future, then don't bother for now.

4. Having a lot of variables with almost identical names (sensVal#, analogSens#) in general indicates bad design; you should consider avoiding so many variables in the first place, and when you really need them all at the same time, then consider an aggregate, such as an Array. Doing so your code will turn out to be more concise, clearer, and less prone to typing errors.

5. A method that is intended to obtain some values, such as sampling(), normally should make those values available to the other methods and properties of the class; yours doesn't, it has type void, and the only thing coming out of it is a complex string going to the screen. There are many ways to provide values, the obvious one is by using a return statement (you could return an Array of floats, of a List of doubles, or whatever suits you); alternatives are "out" parameters (don't abuse those!), and in some cases class-level variables (not recommended here). I hope you notice how this fits well with the previous comment.

6. You should not export information through a GUI element (such as a TextBox), except towards the program user; a program that shows information to the user in one part of the code, and then tries to regain that information from the GUI is extremely bad design. You should rely on data structures, what the user sees should be an afterthought, and not an essential part of operation.

7. Over time you will learn to carefully choose identifier names; GetAnalogValue() is good, sampling() is not.


Keep learning!

Smile | :)
Luc Pattyn [My Articles] Nil Volentibus Arduum

AnswerRe: Split a String of numbers in textfield Pin
Richard MacCutchan9-Feb-18 21:58
mveRichard MacCutchan9-Feb-18 21:58 
Questionmodeling n-variable polynomial where n isn't known until runtime Pin
Alexander Kindel9-Feb-18 10:06
Alexander Kindel9-Feb-18 10:06 
AnswerRe: modeling n-variable polynomial where n isn't known until runtime Pin
Alexander Kindel10-Feb-18 4:03
Alexander Kindel10-Feb-18 4:03 
QuestionI do not know English very well, so my question may be incomprehensible .I wanted to create a program that should determine the frequency of spreading it. Pin
Bek Boltayev9-Feb-18 9:48
Bek Boltayev9-Feb-18 9:48 
AnswerRe: I do not know English very well, so my question may be incomprehensible .I wanted to create a program that should determine the frequency of spreading it. Pin
Pete O'Hanlon9-Feb-18 10:10
mvePete O'Hanlon9-Feb-18 10:10 
QuestionHow can I create a program that shows information on DVB-T2 USB and shows it in a noutbook ??? Pin
Bek Boltayev9-Feb-18 9:42
Bek Boltayev9-Feb-18 9:42 
AnswerRe: How can I create a program that shows information on DVB-T2 USB and shows it in a noutbook ??? Pin
Dave Kreskowiak9-Feb-18 13:27
mveDave Kreskowiak9-Feb-18 13:27 
QuestionMultiple sliders or trackbars Pin
Member 136704429-Feb-18 8:07
Member 136704429-Feb-18 8:07 
QuestionRe: Multiple sliders or trackbars Pin
Maciej Los9-Feb-18 9:03
mveMaciej Los9-Feb-18 9:03 
AnswerRe: Multiple sliders or trackbars Pin
ZurdoDev9-Feb-18 9:10
professionalZurdoDev9-Feb-18 9:10 
AnswerRe: Multiple sliders or trackbars Pin
BillWoodruff10-Feb-18 23:23
professionalBillWoodruff10-Feb-18 23:23 
GeneralRe: Multiple sliders or trackbars Pin
Member 1367044211-Feb-18 12:59
Member 1367044211-Feb-18 12:59 
GeneralRe: Multiple sliders or trackbars Pin
BillWoodruff11-Feb-18 16:56
professionalBillWoodruff11-Feb-18 16:56 
GeneralRe: Multiple sliders or trackbars Pin
Member 1367028512-Feb-18 0:54
Member 1367028512-Feb-18 0:54 
QuestionHow to add a discrete transfer function in C# code? Pin
Member 136703089-Feb-18 5:21
Member 136703089-Feb-18 5:21 
AnswerRe: How to add a discrete transfer function in C# code? Pin
OriginalGriff9-Feb-18 5:27
mveOriginalGriff9-Feb-18 5:27 
Questiongetting same numbers when executing a random number generation method? Pin
auting828-Feb-18 6:47
auting828-Feb-18 6:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.