|
Hi Friends
I would i like question u all abt Generics. I have read abt Generics but there is a doubt & i would i like to question u using simple program.
public class Student<T>
{
private string name = "satish";
private Int16 RollNo = 12;
public void displayStudent()
{
Console.WriteLine(name);
Console.WriteLine(RollNo);
Console.ReadLine();
}
}
class Program
{
static void Main(string[] args)
{
Student<int> s1 = new Student<int>();
s1.displayStudent();
}
}
If i am right then the above Student class is called Generic class. What is the use of creating a class like this if we are using a method & we are just specifying the Type in angle bracket. so Please help me
|
|
|
|
|
Hy,
This MSDN usage definition on Generic Types is the best I think:
- You can use generic types/classes to maximize code reuse, type safety, and performance.
- The most common use of generics is to create collection classes.
List<T> is possibly one of the best example:
It has generic type in that you can create a List of ints, strings... your own defined types.
It has type safety => you can not add "Dan" to a list if ints
It has performance => no need to cast from object to yourType
[EDIT]Here's a better usage of generics for your example:
public class Student
{
private string name = "satish";
private Int16 RollNo = 12;
public void displayStudent()
{
Console.WriteLine(name);
Console.WriteLine(RollNo);
Console.ReadLine();
}
}
class Program
{
static void Main(string[] args)
{
List<Student> students = new List<Student>();
students.Add(new Student());
foreach(var std in students){
std.displayStudents();
}
}
}
[/EDIT]modified on Monday, February 22, 2010 1:12 AM
|
|
|
|
|
hi sir,
Thank u that u replied soon sir But what happens in Memory.
List is of Object type & if i specify <int> Int is of Value type.
Then what exactly happens ?
Thank u once again
|
|
|
|
|
Hy,
you did it all wrong. look at my modified version.
|
|
|
|
|
ya i saw your Program sir. now i understood thank u very much
|
|
|
|
|
I am having a requirement in which i have to create a object of class for only one time in my project . if next time developers try to create a new object for that class it should show error
|
|
|
|
|
Sounds like Singleton to me.
Have a look Here.
Also Google or Bing could help a lot.
|
|
|
|
|
See here.[^]
But be warned that the Singleton Pattern is generally overused; be sure you really need it before you waste time doing it. I have never needed a Singleton.
|
|
|
|
|
Does anyone know of a good Socket Library that extends the .Net Socket libraries. The .net4 Sockets are pretty primitive compared to libraries like Dart and Indy. I am looking for an Open Source project like Indy that has lots of protocols (HTTPS, SSL, SMTP, etc). Sadly, Indy looks to be dormant for .net. Thanks for any help, Rex
|
|
|
|
|
I got a hardisk from which i need to know which are the programmes installed there. OS is corrupt there. Any suggestions how can i find this.
I got the registry file which is located in windows\system32\config but have no idea how to parse it.
|
|
|
|
|
Good people,
I am using Windows Installer with Visual Studio 2008. How do I make uninstallation for my application available in the list of programs (of course right under my program)?
Thanks for any help or insight you can provide.
Blitz
|
|
|
|
|
If you have product code then you can use via
MsiExec.exe /I {"YOURPRODUCTCODEHERE"}If you can think then I Can.
|
|
|
|
|
Hi all,
I have the following gridview which has got a text box for any record entry of data on the grid.
when i want to write some code for the TextBox, I cant see it on the code View.Is there any way i can access Textbox1 on the code associate it with the record on the grid.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="LiveMsg" DataSourceID="SqlDataSource2">
<Columns>
<asp:BoundField DataField="LiveMsg" HeaderText="LiveMsg"
SortExpression="LiveMsg" />
<asp:TemplateField HeaderText="Message">
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Width="1000"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText=" ">
<ItemTemplate>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Button ID="btnSend" runat="server" Text="Send"/>
</ItemTemplate>
</asp:TemplateField>
</column>
</Gridview>
Thanks in advance for your help.
-- Modified Sunday, February 21, 2010 2:16 PM
|
|
|
|
|
When you bind to multiple rows, what would you expect to see with a single ID for the textbox? You can't have multiple items called the same thing so you need to get at it some other way; and that way (unfortunately) is to use the Cells collection of the row you're interested in. This property provides you with indexer access to each cell, so you'll have to refer to something like Cells[0] to get the first textbox (bearing in mind you'll need to cast it to the appropriate type)."WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
I have a service running which runs FileWatchers to detect changes and new accounts.
Currently when a file is received I call my file manager which:
creates the context for incoming db and outgoing db
adds/updates account
submits changes
destroys contexts
My Problem: My service regularly dies on what appears to be the second record stating that the first context failed to connect because it could not log in. This happens when I use the service ID as well as using sa!!! The interesting thing is during debug my SECOND context connected correctly and I could access everything.
This leaves me wondering if I should create the context's at the service start, continue to use them over and over again, then destroy the context only when the service shuts down.
It seems that while it keeps a resource around for a long time, it should be okay since the context functions in a disconnected fashion.
Comments?
Thanks.
|
|
|
|
|
No, you should not create the context when the service starts. Create and open the context when necessary and close it as soon as you are finished, let the connection pool manage when to destroy it.
What credentials are you using in the connection string? Do they have the proper access? You should not be using the sa account. I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I setup the service with it's own ID. Established access and Securables.
I double check the accesses both from my workstation as well as my server using a query tool to ensure I'm connecting the same way the service is.
I start the service then move the files into the folder. The first context ALWAYS fails when created by the service yet succeeds when I use the query tool to connect specifying the same database as my starting database.
When I change the ID to 'sa' I also get the SAME FAILURE. At time I get the service running and it succeeds but later when a new account comes in the service crashes due to login failure.
I've run the debugger against it and the same credentials going against the other database works just fine. When I check the Sql Server log it shows 'login failed for user id {my service id}'.
I'm at a TOTAL loss as to what to do. I've approached this problem from EVERY angle including posting the issue to the MS forums hoping MS can help as well and have yet to find the fix to the problem.
|
|
|
|
|
Member 6966224 wrote: including posting the issue to the MS forums hoping MS can help as well
It's not a Microsoft problem.
Member 6966224 wrote: using a query tool
What tool?
You clearly do not have the proper connection string or are not using it, or the objects, properly. Show what you are doing and maybe we can help point out your problem. I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I downloaded a query tool (not the Sql Manager Studio) to do the test. I'm not at work so I don't know the name. I know it isn't an MS problem but they may be able to provide an answer. Everything there says the connection should work.
|
|
|
|
|
The microsoft forum ended up being a help.
One poster had indicated that the only thing that can be wrong is my connection string.
Well, I looked at every single bit of it after that and opened up my Sql browser and compared table names, database names, etc.
it ends up I had the absolute worst bug to find: I typed an 'o' when I should have typed an 'a'. After that the service ran just fine.
|
|
|
|
|
Hi,
Can anyone tell me how can i retrieve my MS Access database on a webpage by using web service? i need to do this using asp.net in c# language.
thanks.
|
|
|
|
|
And what do you know about web services? Have you done any research? I know the language. I've read a book. - _Madmatt
|
|
|
|
|
dalila y wrote: Can anyone tell me how can i retrieve my MS Access database on a webpage by using web service? i need to do this using asp.net in c# language.
I just finished watching a video[^] on Channel9 - takes 10 minutes of your time. They're using SQL Server and not MSAccess, but it should be enough to get you started I are Troll
|
|
|
|
|
Hello all - I'm curious as to whether anyone on this forum knows of any generics "labs" that exist. Specificially, I'm looking for exercises where I need to come up with a solution and have access to an answer when I get stumped or can find out the "real" (or better) way to solve the question.
|
|
|
|
|
None that I can think of. I know the language. I've read a book. - _Madmatt
|
|
|
|