1
Answer

C# Generic Class - change type parameter.

djmikeymike

djmikeymike

18y
2.8k
1
Hi All,

I am on a learning curve from .net 1.1 to 2.0 and I am trying to get my head around generics.

As an excercise I am trying to create a linked list that can store data of multiple types.

As such I have created class Node<nodeDataType> and class MyLinkedList

I want to use the list class like this:

MyLinkedList ll = new MyLinkedList();

ll.append<string>("foo");
ll.append<
Exception>(new Exception());
ll.append<
short>(-11);

My problem is this:

The MyLinkedList class needs to store a head node (private Node<???> _headNode;) which is null when created, and the type of object to be stored is not known until the first item is appended.

Is there a way of specifiying the type of a generic class at runtime or indeed changing the generic class type at runtime?

Cheers,

Mike.
Answers (1)
0
Laxmidhar Sahoo
NA 2.3k 1.4k 7y
<b> Report Date:&nbsp;&nbsp; 2016-11-21 &nbsp;&nbsp;Optometrist: &nbsp;&nbsp;start &nbsp;&nbsp;Time:&nbsp;&nbsp; Consultant: &nbsp;&nbsp;Dr.suresh</b>
0
Midhun T P
NA 19.7k 281.2k 7y
Hi,
 
Please try below query - 
  1. DECLARE @x XML = '<table WIDTH="100%" CELLPADDING="1" CELLSPACING="1">  
  2.    
  3. <tr style="COLOR: black; FONT-FAMILY: Arial; FONT-SIZE: 10pt;BACKGROUND-COLOR: #f2f2f2;">  
  4.    <td><b>Report Date : </b>2016-11-21 </td>  
  5.   <td><b>Optometrist : </b> </td>  
  6.   <td><b>Start Time : </b> </td>  
  7. </tr>  
  8.    
  9. <tr style="COLOR: black; FONT-FAMILY: Arial; FONT-SIZE: 10pt;BACKGROUND-COLOR: #f2f2f2;">  
  10.         <td><b>Consultant : </b>Dr.Suresh </td>  
  11. </tr>  
  12.    
  13. </table>'  
  14.   
  15. SELECT t.c.value('.''NVARCHAR(MAX)')  
  16. FROM @x.nodes('*') t(c)  
 
Reference :
https://stackoverflow.com/questions/38868364/sql-remove-all-html-tags-in-a-string