|
Wow ! ! !
Thank you ! ! !
You seem to be an absolute expert.
But two new questions arise: -))
1.
From where can I get such know-how? Is there any good book/paper available on such details?
2.
How can I restrict my Generic Type <t> to the basic datatypes as e.g.: char, int, double,..
fct<t>( T value ) where T: ...basic numeric types only ...
Kind regards
-- modified at 7:27 Thursday 17th August, 2006
|
|
|
|
|
Tomerland wrote: From where can I get such know-how? Is there any good book/paper available on such details?
*blush* I googled it. I've only really used generics for typed containers, I was interested enough to know more that I was willing to spend a little time researching it and playing with a sample app.
Tomerland wrote: How can I restrict my Generic Type to the basic datatypes as e.g.: char, int, double,..
http://msdn2.microsoft.com/en-us/library/d5x73970.aspx[^]
It looks to me like it's not possible.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hello
Christian Graus wrote: It looks to me like it's not possible
I believe it is. This method should only work with int and double types only
private void CreateMethod<T>() where T : IComparable<int> , IComparable<double>, new()
{
T instance = new T();
MessageBox.Show(instance.ToString());
}
Regards
|
|
|
|
|
This won't compile as you put IComparable twice. However, one fixed, it seems to work with only numeric types. I had no idea you could put
int n = new int();
It seems kind of redundant to me.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hello
Actually there was an error due to CP script. Sorry I have to remove the pre tag. Here is the correct code
private void CreateMethod<T>() where T : IComparable<int> , IComparable<double>, new()
{
T instance = new T();
MessageBox.Show(instance.ToString());
}
and why you call the new() redundant?? How would you declare your types in the method otherwise??
Regards
-- modified at 8:41 Thursday 17th August, 2006
|
|
|
|
|
T instance; ( if T is an int or a double. )
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Yeah, I didn't know you could use new with value types either. I guess I've just never tried.
|
|
|
|
|
hi guys!
need some help..
i have to make a management console type application which will install software on remote machines in a network .. using c#
can any one tell me where to start from..any useful links or tutorial etc..
will using winsock is a good idea?
abhinav
|
|
|
|
|
Hi.
I have created a class that read data from the database and i want to display this data on labels.
here is my class
public void SeachProduct(string PBarcode,string PName,string PPrice)
{
Barcode = PBarcode;
ProductName = PName;
Price = PPrice;
SqlConnection conn1 = new SqlConnection();
conn1.ConnectionString = "integrated security=SSPI;initial catalog=Phusa;server = za211149;persist security info=False";
conn1.Open();
try
{
SqlCommand cmdSearch1 = new SqlCommand();
cmdSearch1.Connection = conn1;
cmdSearch1.CommandText = "SELECT ProductName,Price FROM Products WHERE Barcode=@Barcode";
SqlParameter Bar = new SqlParameter();
Bar.ParameterName = "@Barcode";
Bar.Direction = System.Data.ParameterDirection.Input;
Bar.Value = Barcode;
cmdSearch1.Parameters.Add(Bar);
SqlParameter Nam1 = new SqlParameter();
Nam1.ParameterName="@ProductName";
Nam1.Direction = System.Data.ParameterDirection.Output;
Nam1.Value =ProductName;
cmdSearch1.Parameters.Add(Nam1);
SqlParameter Pri= new SqlParameter();
Pri.ParameterName = "@Price";
Pri.Direction = System.Data.ParameterDirection.Output;
Pri.Value = Price;
cmdSearch1.Parameters.Add(Pri);
SqlDataReader dr1 =cmdSearch1.ExecuteReader();
if(dr1.Read()==true)
{
//MessageBox.Show("Product found");
ProductName= dr1["ProductName"].ToString();
Price = dr1["Price"].ToString();
}
else
{
MessageBox.Show("Product not found");
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn1.Close();
}
and here i am try to call so that it can display data on the labels my class on form
SearchCustomers search = new SearchCustomers();
string Barcode;
string ProductName="";
string Price = "";
Barcode = txtBarcode.Text;
search.SeachProduct(Barcode,ProductName,Price);
lblProductName.Text = ProductName;
lblPrice.Text =Price;
}
-- modified at 4:03 Thursday 17th August, 2006
|
|
|
|
|
To make your code work as it is now, you have to use the "ref" keyword on the parameters, so that the method can change the strings that you send into it:
public void SeachProduct(string PBarcode, ref string PName, ref string PPrice)
and
search.SeachProduct(Barcode, ref ProductName, ref Price);
To use reference parameters in this ways is rarely used, though. Store the values in the search object instead, and expose them through properties.
---
b { font-weight: normal; }
|
|
|
|
|
I can't create uninstal project in my .NET 2003 Setup and Deployment Project. How can I do it?
Thank you for your help...
This is my sign
|
|
|
|
|
Hello
Wait a minute!! I thought setp program does that for you?!! Check the Add/Remove programs in the control panel after you install your app. Otherwise why would you make a setup?!!!
Regards
|
|
|
|
|
I am displaying images in my application. I want to display the images dynamically by assigning absolute path to the image controls. When i deploy my application in the web server, i could'nt view the images in the browser since it checks for the clients local path. How to solve this.
Thanks in advance.
Saravanan. P
|
|
|
|
|
This is a web app ? If so, how are you managing to load images locally ? If not, how are you loading them and how does the server fit in ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Thanks for immediate reply.it is web app developed using c#.i am dynamically assigning the absolute image path ( like c:/bat.gif ) to image controls at runtime.after depolying, my app is searching for bat.gif in client machine but i want my app to search for bat.gif in server machine and display it.How can i do it.
|
|
|
|
|
You need to point to the images using the path to the server, such as www.mysite.com/images/img.gif. If you put a local path, then you'll get a local path.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Any images that you want to display have to be accessible through the web server. You have to use the virtual address of the image, not the physical address, as the browser will be getting the image through the web server, not through the file system.
---
b { font-weight: normal; }
|
|
|
|
|
Thanks for immediate reply.
|
|
|
|
|
Hi all,
Is it possible to send a file directly to a printer in C#?
Thank you in advance.
"Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison
|
|
|
|
|
Can any one please tell me how to implement flat files with NHibernate. I dont want to use the database with NHibernate. I wanted to use the flat files to save the data using the NHibernate.
Rakesh
|
|
|
|
|
plz any body tell me how i can add items to listview control with a sample C# project.
|
|
|
|
|
|
use a ListViewItem property for the list view u have
ListViewItem item;
item=new ListViewItem("cchandru");
items.SubItems.Add("kanth");
YourListviewControlName.Items.Add(item);
even i had this problem before..lol
cheers,
Chandru.
|
|
|
|
|
how i can add bitmap images to ListView Control e.g Folder Image
plz give me an idea about that.
thanx
|
|
|
|
|
u have to add a image list to the listview control property and then in the list view item property u add the image.
ListViewItem item;
item = new ListViewItem("Chandru",O);
/*
tht zero represents the image tht has to be added to this column from ur image list
0 -> 1st image in ur image list collection
1 -> second image.
*/
Am i clear to u?
|
|
|
|