|
mschuckmann wrote: If you leave out the where constraint you've essentially specified a generic with a constraint of object and you can't call any methods except those declared by object. Therefore my example code will not compile without the where constraint. So sure you can impliment generics without type constraints but don't expect to do anything interesting in your generic code.
I do agree to your point of view, that the limitation of generics in regard to derived classes are unexpected. As a workaround you can use an interface, that defines the required methods, as the constraint. However, you must explicitly specify the interface for each class:
interface Named
{
void Name();
};
class Base : Named
{
public void Name()
{
Console.WriteLine("I'm a Base class");
}
};
class Middle : Base, Named
{
public new void Name()
{
Console.Write("I'm a Middle class");
}
};
class Child : Middle, Named
{
public new void Name()
{
Console.Write("I'm a Child class");
}
};
class Program
{
static void PrintName<T>( T instance ) where T : Named
{
instance.Name();
}
static void Main( string[] args )
{
Child c = new Child();
PrintName( c );
Console.ReadLine();
}
}
Regards,
Tim
|
|
|
|
|
I am trying to Bind data to DropDownLists and a CheckBox on differents Views of the MultiView. However I get an error whenever I try to Bind the Data. I did it in the Code Behind but cannot figure out what event in what object I should be putting the code in. Can anyone assist?
~Candi
|
|
|
|
|
Hope the Article by verinder bindra here[^] in CP will help you.
Regards,
Satips.
|
|
|
|
|
I have to insert 173 values from a DataTable into 173 existing fields in a SQL table. The values are of all different types. Any suggestions on doing this without taking a very very long way? Thank you!
Vicky
|
|
|
|
|
kissa49 wrote: Any suggestions on doing this without taking a very very long way?
By writing a simple C# program to do it?
|
|
|
|
|
right. i can just do an insert statement, except i have 173 fields and i have to specify each name and cast each data type
Vicky
|
|
|
|
|
Do you have a specific problem you need solving because we'll need more information if we're to help you?
|
|
|
|
|
Find your DBA, and ask him to write you a stored procedure for the insert on his massively dumb table, 173 columns is insane!
|
|
|
|
|
Yes, its a general table that gets normalized later. I have a DataTable containing the data that needs to go into this table. i was trying to do SQLBulkCopy, but that wouldnt work before the fields in the SQL table are of different data types and what goes in are Strings. So... I was trying to do insert SQL statements from the code.
Vicky
|
|
|
|
|
What's the source of the data? How does it get into the DataTable?
|
|
|
|
|
I write it into the table from a txt file
Vicky
|
|
|
|
|
When I have to do something like that I use bcp , the SQL Server command-line utility for bulk copy, to load the raw data into a (temporary) table and I have a trigger on the table that handles converting and moving the data to the actual destination(s).
Be sure to specify -h"FIRE_TRIGGERS" when running bcp .
|
|
|
|
|
perhaps you would like to share some details on that trigger?
Thanks.
Vicky
|
|
|
|
|
Sure, I'll work up an example if you like.
-- modified at 20:12 Tuesday 3rd July, 2007
And is it CSV or some other format?
|
|
|
|
|
The data is already in a DataTable in strings. I need to transfer that data into fields into an existing SQL table. The fields are all set to different data types so I have to cast the strings to whatever the fields are.
Vicky
|
|
|
|
|
hi guys, I need help to read a block of data from a text file.
I m using StreamReader object and its method ReadBlock, which is supposed to write certain number of characters into a char[] buffer, but when I debug the code actually the buffer is not being written, all the values are empty.
Please help.
|
|
|
|
|
Show the code, including var declarations and initialization, plus any errors/exceptions.
Does it work at all ? up to a point ? or what ?
|
|
|
|
|
How to pass user defined oracle type as argument to a stored procedure using c#. anyone pls help.
|
|
|
|
|
Dear All,
We have a requirement in our MDI application wherein we have to load the child form with all the master data (from DB) only once. Basically after the form is loaded the first time, the subsequent instances need to load very quickly and not query the DB again.
I am not sure how we can achieve this in MDI. Can you give your valuable suggestion?
Please let me know incase you have additional queries.
Thanks and regards,
ATUL
|
|
|
|
|
Implement a singleton pattern for your db class and cache the db query
only two letters away from being an asset
|
|
|
|
|
If your using DataSet's to retrive the data then you can cache them. The next time the app needs the data it just grabs the cached DataSet.
|
|
|
|
|
Does anyone have a good tutorial or reference as to how to implement a website search function? I used to doing this in coldfusion with verity search and just wanted to know how to go about doing so in .net C#. Thanks in advance to all that reply.
|
|
|
|
|
|
Hey!
I have some performance problems when I am using a third party dll to read and write to a GSM phone. I first used these commands to read and write in my main thread and noticed that when executing these commands, the application froze for a couple of seconds. The commands worked but the behavior was annoying. I then thought that running these commands in threadd separated from the main thread would solve the problem but it didn't. The application still freezes when using the read and write commands. Does anyone have any idea why? I though threads would solve these kinds of problems.
/Hampus
|
|
|
|
|
Hi,
First of all I assume it is working ?
And I hope the DLL is not doing some GUI stuff of its own.
I guess you only have the DLL, that is not the source, nor a technical description.
You could have a look at the CPU load it creates: open Task Manager, Performance tab
and watch the curve while trying to read/write the GSM. If its close to 100% then
they probably have a busy loop, which is harming your main thread's behavior.
If so, you may try to set a lower priority for that thread;
gsmThread.Priority=ThreadPriority.BelowNormal;
that should solve the GUI part, but may cause the GSM DLL to malfunction...
If CPU load isnt high, they somehow execute (part of) their stuff on the main thread anyhow,
and your thread is pointless.
|
|
|
|