|
Exactly. That's a bug in the language specification of C# which can cause bugs in the software which are very hard to find. Fortunately, ReSharper can issue a warning. And a well designed style guide should suggest different styles for fields vs. local variables.
|
|
|
|
|
I have the following code, but the class member "X" refuses to be serialized to the xml file:
[Serializable]
public class MyList : List<MyClass>
{
public string X = string.empty;
}
protected void Function()
{
MyList L = new MyList();
L.X = "String";
XmlSerializer serializer = new XmlSerializer(typeof(MyList));
StreamWriter Sw = new StreamWriter(Filename);
serializer.Serialize(Sw, L);
Sw.Dispose();
}
The member is simply absent from resulting the Xml file.
Is there anything I can do to force the serializer to serialize member "X" to the file?
Is there some reason it's not serializing "X"? Is it because the class derives from List<T>?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Richard Andrew x64 wrote: The member is simply absent from resulting the Xml file. The member is a field, not a property.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
OH!
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Looking at that, I had to wonder if you were trying C#6 property syntax and just forgot the => instead of = .
This space for rent
|
|
|
|
|
how to get the longest distance between equal number in the array using c#
|
|
|
|
|
Do you expect other's to write the code for you? It ain't work so here.
But it is quite simple. Give it a try:
Iterate over the array items using another iteration for each item looking for equal numbers. With equal numbers get the distance and check if it is larger than the previously detected maximum distance.
|
|
|
|
|
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.
Try it yourself, you may find it is not as difficult as you think!
But without giving you any code, I'll tell you how I'd do it: I'd create a struct to hold each distinct value and a sorted list of indexes in the array. I'd then fill out a collection of such structs - one for each distinct value in the array - and traverse the collection when complete to find the largest difference in indexes.
If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.
As programmer, your job is to create algorithms that solve specific problems and you can't rely on someone else to eternally do it for you, so there is a time where you will have to learn how to. And the sooner, the better.
When you just ask for the solution, it is like trying to learn to drive a car by having someone else training.
Creating an algorithm is basically finding the maths and make necessary adaptation to fit your actual problem.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
any one work on sentiment analysis through google cloud library???please help
|
|
|
|
|
Member 12875047 wrote: please help
With what?
We have no idea what you have tried, what happened when you did, or what help you want from us.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Sentiment analysis indicates that your post is not to be taken seriously due to its lack of capitals, improper punctuation, tone, etc.
|
|
|
|
|
Here[^] you go.
This space for rent
|
|
|
|
|
Member 12875047 wrote: please help
Help on what ?
You gave a question a problem ?
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
Hi, I'm creating a custom VScrollBar and I have problem getting the exact Y position of the thumb like the Windows.Forms.VScrollBar, I have searched online and I found some examples of custom scrollbars like:
How to skin scrollbars for Panels, in C#[^]
Custom Drawn Scrollbar[^]
The problem with these examples are that they don't get the exact top position of the thumb comparing to the windows scrollbar. I am getting a Top position that while scrolling becomes less than the real position
Doesn't anyone know how to calculate this?
|
|
|
|
|
Member 10498254 wrote: Doesn't anyone know how to calculate this? How are you calculating it?
|
|
|
|
|
I'm calculating it like this
decimal ratio = (decimal)((ClientRectangle.Height) - 2 * topButton.Height - ThumbSize()) / (Maximum - Minimum);
int thumbTopPosition = (int)((Value - Minimum) * ratio) + topButton.Height;
|
|
|
|
|
And what is wrong with the result?
|
|
|
|
|
the problem is that the Y position I get is smaller than the position of the Windows Scrollbar.
I tested my custom scrollbar with the Windows scrollbar with the same Maximum, Minimum, LargeChange and SmallChange, and when I get a Y position of 45 the other has a Y position little bit bigger than 45. The difference between the Y positions gets bigger as a set the Maximum value bigger.
|
|
|
|
|
I can only assume that your calculation is missing or adding something that Windows includes/excludes.
|
|
|
|
|
I'm thinking exactly the same. I'm missing something that windows includes. I hope I can figure it out.
|
|
|
|
|
and what is in the ThumbSize method?
I would avoid the decimal type, what you need is either float or double, since ratio could be a very small number; decimal is fine for monetary amounts, not for arbitrary scaling. Have you ever looked at the actual values while debugging?
modified 31-Dec-16 8:05am.
|
|
|
|
|
|
Hi Richard, all is fine, except for the scrollbar never reaching the bottom...
|
|
|
|
|