|
Hi!
Please, help me! I would like to create List<t>, for myType in runtime(for example, Int32):
Type myType = Type.GetType("System.Int32");<br />
List<myType> list = new List<myType>();<br />
- compiler is throwing errors:"The type or namespace name 'myType' could not be found (are you missing a using directive or an assembly reference?)"
How can I create such list for this type?
modified on Tuesday, July 8, 2008 9:42 AM
|
|
|
|
|
You can't. The generic type has to be known at compile time.
What is it that you are trying to accomplish?
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Guffa wrote: You can't. The generic type has to be known at compile time.
Not quite. A generic type can still be created with reflection at runtime.
|
|
|
|
|
You can create a generic type with reflection at run time. However, I am not sure what use it would be to you.
Eg: Activator.CreateInstance(typeof(List<> ).MakeGenericType(yourtype))
|
|
|
|
|
Hi, I'm looking to create an executable file that I can load on my windows mobile Symbol device that'll delete everything that I don't need. The problem is that I'm not familiar at all with working with windows registry within code. This is my first time using c#, however I'm fluent in Java which I've heard is similar. Can someone give me a start on the code such as a method used to delete a registry key and a method used to delete a file.
Thanks in advance!
|
|
|
|
|
Here u Go it's here in CodeProject
[^]
Have Fun
Never forget it
|
|
|
|
|
umm after looking here I need some help as I've never written in c# before. Is there a way I can just hardcode what I need. I just want something simple for now that I can type in what I need and it will delete it. When I look at
[code]
try
{
// Setting
RegistryKey rk = baseRegistryKey;
RegistryKey sk1 = rk.CreateSubKey(subKey);
// If the RegistrySubKey doesn't exists -> (true)
if (sk1 == null)
return true;
else
sk1.DeleteValue(KeyName);
return true;
}
[/code]
it seems that when I'm cteating the Registry key rk and deleting it, it's doing nothing more then deleting what I made, even though I didnt call new. Could someone help me out.
|
|
|
|
|
This whole project is for windows mobile as I said before... I've been thinking about whether it would be easier to use a registry file (.reg file) to delete the registry entries that I would need to delete, and then just delete the files with the delete method.
Help please!
|
|
|
|
|
Maybe this can help u :
[^]
Have Fun
Never forget it
|
|
|
|
|
Thanks! I understand it more now. But i need to know is it possible to edit the registry in windows mobile 5.0 through an exe file or do i need to download a refistry editor?
|
|
|
|
|
Hi,
I used sql 2005 as my backend.
How do i check the MAX(of a field) in a table in from C# codes
|
|
|
|
|
if one stores data in a DATATABLE it's easy to see that :
DataTable DT;
DT.Columns.Count;
Have Fun
Never forget it
|
|
|
|
|
|
I think you want to get the max value of a column from a table in sql server?
select max(column_name) from table
You run this as an executescalar in your c#
hope this helps
Bob
Ashfield Consultants Ltd
|
|
|
|
|
is there a way to Listen to all Port's
Like the Ip Case ( IPAddress.Any )??
Have Fun
Never forget it
|
|
|
|
|
I'm using C#, .net2.0 framework and DB2 as my database.
I need to validate a database(DB2) query which is given by the user in the textbox. Please note that I just need to validate not to execute the query(text in textbox). I dont want any third party software and I want to do in .net2.0, ASP.net, C#, DB2
Please share your ideas and solution.
|
|
|
|
|
if you're using any kind of a dataSet u can create a shallow copy of it
and without "Thouching" the original Exe the Qurey for test only
use the try and catch finlly
Have Fun
Never forget it
|
|
|
|
|
thanks for your reply..
Could you please tell me how to do in .net2.0 with c#. If you provide steps or code is very helpfull for me..
Thanks in advance
|
|
|
|
|
Does db2 have the query parse facility like sql server? This allows you to parse the sql without executing. If so then you should be able to wrap it up in a try/catch and display any problems.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
thanks for your reply..
I'm not aware of sql parser in .net.. Could you please tell me how can i get it so that I can test the same with DB2 also..
Thanks in advance
|
|
|
|
|
The parser is not a .net feature, it's a sql server feature - SET NOEXEC ON. By doing this, when you execute your sql it simply parses but does not execute. I don't know if db2 has a similar feature?
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Does anyone know how I can encode a string to a CP865 encoded text, (not for example Unicode or UTF8).
What I am trying to do is to transfer a string content as an txt file with CP865 encodeing.
Response.ClearContent();
Response.AddHeader("Content-disposition", "Attachment;filename=Myfile.txt");
Response.ContentType = "text/plain";
Response.Write("This text shall have de Norwegian charset of the CP865 encoder");
Response.End();
Thanks
Thomas
|
|
|
|
|
You can convert to a specific codepage using the Encoder class:
byte[] bytes = Encoding.GetEncoding(865).GetBytes("This text shall have de Norwegian charset of the CP865 encoder");
You may also need to specify the encoding in your response header.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Thanks, it worked great
Here's a example of my final solution, if anyone else ever needs it.
int chunkSize = 10000;
MemoryStream ms = null;
int dataLeft = 0;
try
{
Response.ClearContent();
Response.AddHeader("Content-disposition", "Attachment;filename=Myfile.txt");
Response.ContentType = "text/plain";
byte[] bytes = System.Text.Encoding.GetEncoding(865).GetBytes("This text shall have de Norwegian charset of the CP865 encoder");
dataLeft = bytes.Length;
ms = new MemoryStream(bytes);
while (dataLeft > 0 && Response.IsClientConnected)
{
byte[] currentChunk = new byte[chunkSize];
int currentChunkSize = ms.Read(currentChunk, 0, chunkSize);
Response.BinaryWrite(currentChunk);
dataLeft -= currentChunkSize;
currentChunk = null;
}
Response.End();
}
catch{}
finally
{
if (ms != null) ms.Close();
ms = null;
}
|
|
|
|
|
I'm trying to create a class that will dynamically load an assembly that will
hold a several definitions for structs (used as an interface to an existing application).
My class will then display those structs as strings - display the interface.
I need to load it dynamically since there are several versions of the same interface.
Thx.
|
|
|
|