16,004,727 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View .NET questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by Chris Trelawny-Ross (Top 28 by date)
Chris Trelawny-Ross
23-May-11 15:14pm
View
Deleted
Um ... two points define a line. You need three to define an angle! :)
Of course,the Atan2() method has an implied third point, but your title seems to omit that little detail.
Chris Trelawny-Ross
16-May-11 12:15pm
View
A C# Question & Answer topic is the wrong place to ask hypothetical questions such as the one you're asking. In C# multiple inheritance simply is not possible - so asking us to "believe it for once" is not going to get much of a response in this section.
In this forum we're only interested in discussing and/or learning about what IS possible in C#, not about things that aren't.
Chris Trelawny-Ross
16-May-11 12:11pm
View
I recommend that you read about interfaces. They are a way of doing things and are available in multiple languages, including C#. Please note that you cannot, in fact, do "the above concepts" (specifically, multiple inheritance) in C#. So interfaces are the only way you can inherit multiple 'things' in C#.
Using interfaces you can inherit a contract - an agreement on the available properties, methods, etc., that the inheriting class must exhibit. Using class inheritance you inherit not only the contract, but also an implementation of those methods.
C# does not allow you to inherit from more than one base class; to inherit multiple contracts (sometimes known as signatures) you must use interfaces to declare the additional signatures, and then implement their behavior in the implementing class.
Chris Trelawny-Ross
13-May-11 15:03pm
View
You should ask this question in a C++ forum. C++ allows multiple inheritance (if I remember right) so you'll find people who've used multiple inheritance who can give you real-life examples of where it helped them. (Or made their lives a nightmare!!)
More usefully, instead of inquiring about applications where the impossible (multiple inheritance in C#) could be used, I would spend some time studying how to use interfaces, and when to use an abstract base class vs. using an interface, for example.
Chris Trelawny-Ross
13-May-11 14:38pm
View
Also (re properties and backing store)...
An 'auto property' is one that is declared like this:
public int ScoreCounter { get; set; }
There is an implicit private field 'scoreCounter' created by the compiler for a property declared like this.
I don't think that Visual Studio has a refactoring that converts a property with backing store to an auto-property. You might download the trial version of Resharper (from JetBrains). It has some awesome refactorings, including the one I mentioned. It also has some really good code inspections - and a handy right margin that if it comes up green you know your code is as 'clean'.
Chris Trelawny-Ross
13-May-11 14:34pm
View
'backing store' is the name given to the private field that is used to actually store the value that a property represents. So, for your ScoreCounter property, the backing store is the 'scoreCounter' variable. The naming comes from the fact that the variable is real storage, that 'backs' the property (i.e. does the real work of the property!) - since the property itself is not truly storage although it is used as if it is a variable of some kind.
Have you tried putting a breakpoint in the timer event handler? If you also put a breakpoint in the mouse move, and set the timer period to, say, 10 seconds, you can (a) force a value into the ScoreCounter (when the mouseMove breakpoint is hit) then (b) when the timer breakpoint is hit look to see if the value is still there.
Am I right in thinking that the mouse move handler is the only place that the score is modified? If not, you should put breakpoints on all the other places that the score is modified. If one of those breakpoints is hit you may have discovered the cause of the problem.
Let me know what you discover.
Chris Trelawny-Ross
6-May-11 18:04pm
View
Deleted
Umm... the string.Format() method (with the format string you're using) will quite nicely give you the hex value of the RGB values you pass in, without having to involve the ColorTranslator.
Am I missing something?
Chris Trelawny-Ross
6-May-11 16:53pm
View
Deleted
Cool recursion!
May I, however, recommend a better name? Other developers using the method probably don't need to know that it uses recursion, so perhaps GetGCD is a better name (communicates the value provided by the method to its consumer).
Chris Trelawny-Ross
25-Apr-11 12:42pm
View
Deleted
If you want to preserve the other properties of sub1, you shouldn't assign it to a double; you should make dummy a ScorableSubject or a var (which amounts to the same thing).
By assigning it to a double you are deliberately saying "get rid of all the non-number parts of sub1". If you want that data to hang around, don't assign it to a double.
The fact that when you explicitly convert a ScorableSubject to a double you are left only with a double is what compilers do. You should not expect anything different ... and if you want different behavior you should write different code.
Chris Trelawny-Ross
25-Apr-11 10:35am
View
Deleted
Albin,
I'm not sure what I violated: my object is still strongly typed. When you assign to a variable of type double (your 'dummy') you are not 'degrading' the object to a value type. If you want 'dummy' to still be a ScorableSubject, you should type it as ScorableSubject, or var. Typing dummy as double tells the compiler that you specfically want to convert subject1 to a double. This is not 'degrading' the object, its a very deliberate conversion that you are asking the compiler to do for you. And please note that 'dummy' is, in fact, still typed. Just because it is a value type does not mean it has no type. Value types are just as much types as class types are!
Chris Trelawny-Ross
20-Apr-11 20:19pm
View
Bobjanova is right - RTF only uses single backslashes. The following expression works to match a an underlined passage in RTF with ONLY ONE UNDERLINED PASSAGE - but it does not falsely trigger on \ul or \ulnone in the 'real text': (?<=(?<!\\)\\ul ).*(?=(?<!\\)\\ulnone). (The nested '(?<!\\)' expression rejects the '\' that escapes the '\' in the 'real' text.
Unfortunately, this breaks if there are more than one underlined passage in the RTF. However, this can be remediated by performing a second regex pass on the matched text, capturing only the text preceeding the first '\ulnone' (if any).
Chris Trelawny-Ross
9-Apr-11 12:32pm
View
Deleted
Ummm .. you say that your code doesn't use expression trees - but I see use of Expression<...>.
What am I missing?
Chris Trelawny-Ross
8-Apr-11 13:32pm
View
Deleted
Reason for my vote of 5
Elegant and simple. Nice.
Chris Trelawny-Ross
20-Jan-11 13:05pm
View
Deleted
Reason for my vote of 5
Good to learn about something I can do with the App Manifest. Thx
Chris Trelawny-Ross
28-Dec-10 14:19pm
View
Deleted
Reason for my vote of 2
You tagged this as C#, but the code is VB.Net
Chris Trelawny-Ross
8-Nov-10 13:20pm
View
I regret to say that delegates don't actually help make your code thread safe, but they do make it type safe. A delegate is an object (can be passed as a variable into a method, can be assigned to a property, etc.) that encapsulates a method - but as well as encapsulating the method it encapsulates the signature of the method. This prevents a method that, say, takes a string as its paramter being used where a method that takes a List is required.
Chris Trelawny-Ross
28-Oct-10 14:25pm
View
Sure, it will convert it to a string. Now do int.Parse(theString) to get the string as an int.
Chris Trelawny-Ross
8-Oct-10 10:29am
View
With that much data, I wonder if any out-of-the-box grid(-like) control will give you the performance you need. I would consider creating a "full" custom control - i.e. where you implement OnPaint to render the visible content. Since you're rendering from a uniform XY grid you can filter the data to be drawn based upon the scroll position (and cell size) - so you'll not be attempting to render the whole grid on every adjustment of the scroll bar.
Chris Trelawny-Ross
23-Sep-10 10:51am
View
I think you'll ultimately need to use both parts, but certainly start with part 1 - perhaps it'll be sufficient. Using an Int32 instead of 32 distinct bool values is a memory and performance optimization. I would start using bool and, when you have your algorithm working, change it to 'pack' 32 bools into a single Int32. If I get some time I'll add an answer with sample code. Regarding using a dictionary - I do NOT recommend using a dictionary; an array will be far more efficient - but you may have to experiment with bool [x,y] and bool [x][y] to see which gives better performance.
Chris Trelawny-Ross
22-Sep-10 18:36pm
View
You found the very words I was looking for, Dave. Do you think he's started writing his program yet? :)
Chris Trelawny-Ross
10-Sep-10 18:05pm
View
I also recommend Googling Double Dispatch and Visitor Pattern. If you really want to learn OO programming, reading the Wikipedia articles, and figuring out what they mean, will serve you far better in the long run than having one of us provide the answer to a test your teacher has set.
Chris Trelawny-Ross
10-Sep-10 18:00pm
View
Sound like you're asking us to solve a problem your teacher has set you. Perhaps asking one of your fellow students what the teacher said in class about Double Dispatch would be the way to go?
Chris Trelawny-Ross
2-Sep-10 17:40pm
View
"why did I ever decide to do software!" ... because in software accidents are generally not fatal? :)
Chris Trelawny-Ross
1-Sep-10 16:59pm
View
Reason for my vote of 1
a. This question was about how to do the first/last thing, so using Linq OrderBy does not address the question at all.
b. Linq OrderBy would not allow the OP to force items into first and last places
c. The OP indicated that his compare routine is significantly more complex than his sample, which would make for an overly large anonymous method.
Chris Trelawny-Ross
1-Sep-10 15:24pm
View
If two items being compared score equally, won't that suppress the sorting on FirstName? The OP also indicated that his sample was simplified compared to his actual Compare routine ... so perhaps adding a trigger on, say, a non-zero score before the score is actually used in the comparison?
Chris Trelawny-Ross
27-Aug-10 19:53pm
View
"Turns out that programming sometimes means writing code, not just using a designer." Who'd have thought?
Chris Trelawny-Ross
27-Aug-10 19:26pm
View
I guess I could call extension methods arcane - but they're totally awesome and as more people get to understand what they offer I suspect that they'll become commonplace.
I find that I'm using them more and more when they improve readability - such as
... if (someString.DoesNotContain("some search text")) ...
which I find to be clearer and safer than the alternative:
... if (!someString.Contains("some search text")) ...
which can be inverted by one accidental character deletion. I consider that the '!' character nestled inside an extension method to be safer because I'm far less likely to be editing the extension method after it's written than I am to be editing the code that uses/would use it.
Chris Trelawny-Ross
8-Jun-10 19:25pm
View
You need to be more specific about what environment you're working in (Windows Forms, or Web) and more descriptive of what you're wanting to do for anybody to be able to help you.
Show More