|
PIEBALDconsult wrote: Interfaces are more flexible, they don't impose a relationship on the classes. If you care to expand on this interesting comment, I'd be very interested to know what the "costs" were of having the "relationship on the classes."
And, if you care to comment, why, in the past, did you use abstract classes rather than just inheriting from a base class ?
thanks, Bill
"Last year I went fishing with Salvador Dali. He was using a dotted
line. He caught every other fish." Steven Wright
|
|
|
|
|
BillWoodruff wrote: "costs"
No, a limitation.
BillWoodruff wrote: base class
An abstract base class -- that shouldn't be instantiated on its own. It depends on the situation.
|
|
|
|
|
I think your question has been adequately answered by Luc.
I would use interfaces over abstract classes for a very simple reason - multiple inheritance is not supported in C#.
No matter whether you use classes or interfaces, what you are doing here is achieving "late binding".
|
|
|
|
|
Using an abstract base class means that you're restricting the objects that factory can create to a particular section of the class hierarchy. whereas using an interface allows any type of object to be created. This can either be a positive scope reducer or a negative restriction depending on context.
An obvious case where using a base class instead of an interface would make sense is a UI related factory, returning Control. Other appropriate cases are more problem specific but basically anywhere where it would make no sense to return something that wasn't in a particular hierarchy, probably because some framework or application code expects arguments of that type, would be an appropriate place to use an abstract (or non abstract, even) class.
|
|
|
|
|
In a C#.net 2010 application, I would like to take
values entered into individual checkbox and place each value of the
checkboxes into separate rows in a sql server 2008 r2 table. I would
also like to use linq to sql for this to occur. Since I am new to
working with linq, I am wondering how I could incorporate linq
into one of the options listed below. Would I need to unload all the
values from the checkboxes into a arraylist. Can you tell me
how to complete this task or point me to utls I can use as a
reference?
Here are some of my code examples:
option 1:
[^]foreach (ListItem item in
((CheckBoxList)Form.FindControl("cblActivities")).Items)
{
if (item.Selected)
{
string Activities += item.Value;
}
} [^]
option 2
[^]
IEnumerable<int> allChecked = chkBoxList.Items.Cast<ListItem>()
.Where(i => i.Selected)
.Select(i => int.Parse(i.Value)); [^]
|
|
|
|
|
A few questions I think can clarify the strategy required for your scenario:
1. are all the CheckBox(es) on the Form in their containers (Form, Panel, UserControl, etc.) at design-time, or do they need to be discovered 'dynamically' at run-time, since they may be created on demand, or they may be created as an outcome of a database query ?
2. is a recursive search necessary because you may have, for example, a panel with CheckBox(es) inside another panel with CheckBox(es), or similar ?
3. at this point ... independent of whether CheckBox(es)are all fixed at design-time, or added at run-time ... is there anything preventing you from adding each CheckBox to a List<CheckBox>, or multiple generic Lists of that Type ... if you need to segregate them in functional categories ?
"Last year I went fishing with Salvador Dali. He was using a dotted
line. He caught every other fish." Steven Wright
|
|
|
|
|
In response to your questions:
1. The values for the checkboxes are discovered dynamically at runtime by running a database query.
2. The checkboxlist control is used. The recursive search is required since I need to know what checkboxes are selected. The user basically reads a letter from the customer and supplies the check marks by the applicable subcompanies.
3. I do not need to segregate the checkboxes into functional units.
Basically if 10 boxes are checked by subcompany, I need to add each checkbox area into a separate row in the Plans table. Basically if there are 10 boxes checked, I need to add 10 rows to he Plans table.
|
|
|
|
|
I apologize: I don't think I studied your question thoroughly enough before posing my questions, and did not fully understand the importance of the Linq=>SQL aspect of it.
While I do know what an ASP.NET CheckBoxList is, I have not programmed one directly myself.
My impression, at this moment, is you are describing a data-entry situation where an operator pulls up a Web Form (probably by a database query of some kind) populated with a certain number of CheckBoxLists, or one CheckBoxList, and then, based on scanning a customer letter, checks various CheckBoxListItems, and then you wish to iterate all that are checked, and map which CheckBoxLists have checked entries, and which entires are checked, into a Database table "Plans" in one or two different ways.
There are folks here who are truly expert on ASP.NET that I'm sure will respond.
Hope my responses were not distracting.
best, Bill
"Last year I went fishing with Salvador Dali. He was using a dotted
line. He caught every other fish." Steven Wright
|
|
|
|
|
I had a class written like this:
public void Set<T>(string key, T value)
{
if(value == null)
{
return;
}
...
}
I'm using "reSharper" however within my visual studio (for those who don't know, resharper is a great little tool that helps clean up code and suggests better ways of writing it. Highly recomend it) to help clean up my code, and ReSharper suggested I write the first line of the above code in the following manner:
public void Set<T>(string key, T value) where T : class
What does this "where T : class" mean? I don't understand what it does.
Thanks
|
|
|
|
|
|
I'm not sure if I'm overlooking something here... this "WriteDat" variable is the byte array that I plan to use to write to the memory chip. the variable "nudSerialNumber" is the numericUpDown control that consists of new serial number. I need to plug the serial number into Writedat (without over-writing the first 2 MSB bits). Its in little edian value. (3rd line inside bracket is what threw an exception.)
void InsertSerialNumber(ref byte[] WriteDat)
{
byte[] serialNumberBytes = new byte[2] { WriteDat[0x60], WriteDat[0x61] };
Array.Reverse(serialNumberBytes);
Int32 serialNumberInt = BitConverter.ToInt32(serialNumberBytes, 0);
serialNumberInt &= 0xC0;
int newSerialNumberIntToWrite = (int)(nudSerialNumber.Value);
newSerialNumberIntToWrite |= serialNumberInt;
serialNumberBytes = BitConverter.GetBytes(newSerialNumberIntToWrite);
Array.Reverse(serialNumberBytes);
Array.Copy(WriteDat, 0x60, serialNumberBytes, 0, 2);
}
To clarify this:
WriteDat: 1111 1111 1111 1111 (no serial number applied)
New Ser#: 0000 0000 1010 0011 (serial number from nudSerialNumber
WriteDat: 1100 0000 1010 0011 (new serial number applied)
^^ (first 2 MSB is untouched)
|
|
|
|
|
Your byte array is only 16 bits long and you try to convert it to a 32 bit integer?
Maybe ToInt16 would be more appropriate (ToInt32 expects a 4-byte array)?
Mark Salsbery
|
|
|
|
|
when you say
Blubbo wrote: 3rd line inside bracket is what threw an exception
my guess is that you are refering to this line of code:
Int32 serialNumberInt = BitConverter.ToInt32(serialNumberBytes, 0);
BitConverter.ToInt32 is looking to read 4 bytes of information and you are only giving it 2 bytes. Try instead using BitConverter.ToInt16 which is designed for the 2 bytes that you are passing in.
BitConverter.ToInt32[^]
BitConverter.ToInt16[^]
best of luck.
as if the facebook, twitter and message boards weren't enough - blogged
|
|
|
|
|
Why are you jumping through hoops like that?
This code may be wrong due to endianness, which you reverse several times over and then apply a weird mask that seems to assume wrong endianness.. anyway I'm going to assume that WriteDat[0x60] is the least significant byte and WriteDat[0x61] is the most significant byte.
int newSn = ((WriteDat[0x61] << 8) & 0xc000) | (0x3fff & (int)(nudSerialNumber.Value));
WriteDat[0x60] = (byte)newSn;
WriteDat[0x61] = (byte)(newSn >> 8);
By the way, why is that byte array passed by ref?
|
|
|
|
|
Do you have any idea how to create IE plugin which will save to log file time of page load? This plugin should report start time (when user clicks go button) and end time (when page is completely loaded).
I prefer .net framework examples, but if you have other ideas, please fell free to post them
|
|
|
|
|
This has already been posted to Q&A; please do not post in multiple forums.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
So I've been reading along in a delightful book, Programming Microsoft SQL Server 2008, for months now, and decided to try out a few of the samples in the text. I fired up VS2010, then tried to add references to the two required assemblies - Microsoft.SqlServer.Smo and Microsoft.SqlServer.SmoExtended. They don't friggin' exist! The only thing visible in the Add References box is Microsoft.SqlServer.Server, so I figured they must have consolidated things a bit from .Net 3.5 to .Net 4.0. No such luck.
So then I tried changing the project from ver 4.0 to 3.5. I'm told I have to close the solution, then re-open it for the change to take effect. That makes sense, so I follow the instructions like a good sheep. When I reopen the solution, I'm presented with the error, "Warning 1 The referenced component 'Microsoft.CSharp' could not be found."
Where did it go? It's not even in the list to re-add it to the solution! All the other language references are there, but CSharp is now missing. Do I now have to re-install VS2010 to get C# functionality back again? Do I have to go back to VS2008 in order to talk to a database using SMO?
I really should be doing homework, but I needed a break and thought this would be a fun, relaxing evening of exploration. Instead, it's a nightmare...
Will Rogers never met me.
|
|
|
|
|
Microsoft.CSharp is a new reference in Framework 4.0.
If you are using something from this dll, then you will need to remove this code (or find a workaround) when you downgrade.
|
|
|
|
|
Oops. Silly me, I have no idea how to remove a reference once I've added it. Can I simply delete it from the project References folder? Like a lot of beginners, I suppose, I usually just keep adding references and using statements until the error messages go away; it never occurs to me to delete them once I get the project working.
Will Rogers never met me.
|
|
|
|
|
If you look at the references listed in your project explorer and find the Microsoft.CSharp.dll reference, simply right click and delete or remove it and the reference should be gone. If you have any code inside your app trying to use anything from the CSharp.dll you must remove it and try another method as was suggested. Or you can change your app back to .Net 4.0 and everything should be okay again. Unless you are making an app that is designed only to work with XP, there really is no reason to change back to 3.5 or another previous version of the .Net Framework. XP users can simply download the .Net framework 4.0 for free to use your app.
|
|
|
|
|
XP users on SP3 or higher can do. I have an XP machine at home and it won't install .Net 4 (or even 3.5, I think) and I don't feel like downloading however many megabytes of updates to move it onto XP SP3, either.
Is 4.0 included as standard with Windows 7? It certainly wouldn't have been with Vista, and making people download a new version of the Framework to use your app is likely to turn a few people off.
|
|
|
|
|
.Net 4.0 is native to Windows 7, and it's available for download. I usually have my setup.exe determine if .Net 4.0 is installed on the operating system in which my app is being installed too first. If not it will automatically install it for them. Most setup.exe applications that I know of incorporate this now.
|
|
|
|
|
It may be 'available for download' but it's a damn big download (200MB? something like that) and unless someone has a fast connection or really wants your software they'll give up when they see that.
|
|
|
|
|
Typically Bob, this is already downloaded and stored on the CD or DVD in a folder with the rest of the setup application to be used if necessary. During the setup processes it is installed if required. If the user decides to download the application from the internet they should be aware of the possibility other prerequisite software may need to be installed as well and downloaded.
|
|
|
|
|
Now that you have thoroughly pissed of the ide it has arbitrarily removed c#, you must now continue to code using VB. If you continue to irritate the ide you will be retrograded to VB6.
Never underestimate the power of human stupidity
RAH
|
|
|
|