I'm referring to my snippet [Inheriting the stack class](https://www.daniweb.com/software-development/csharp/code/498828/inheriting-the-stack-class) After looong loong searches and many tries and tests, I finally came up with a version that works as I wanted to. Stacker can now handle any type of object, even with arethmetic methods in place. The virtual way as proposed by JOShealV would work as well, but then you had to derive from Stacker and do some overriding. Still two questions though: 1-- How should I handle nullable value types? 2-- What could be returned by the arithmetic methods? Nothing like now, should I throw an exception? Any suggestions more …

Member Avatar
Member Avatar
+0 forum 3

Hello Everyone, Actually i have one question. I create one generic method like below:- public static dynamic ExecuteSelectProcedure<T>(string procedureName) where T: class { SqlDataReader reader = ExecuteSelectCommand(procedureName, CommandType.StoredProcedure); if (typeof(T).FullName.Equals("System.Data.DataTable")) { DataTable dt = new DataTable(); dt.Load(reader); reader.Close(); return dt; } return reader; } Now i want to restrict user to give type name only **SqlDataReader** or **DataTable** for **T** Is it possible? Please give some idea. Thank's

Member Avatar
Member Avatar
+0 forum 2

It comes in handy of course that you can dynamically adjust the size of a List or Dictionary. But this time I want to use a Dictionary with sizes from 1 to 8. When I have e.g. size 3, it will stay that way. On the net I found a solution to use a wrapper class around a Dictionary, which could do the job. Should I resort to an array instead, or are there still other options?

Member Avatar
Member Avatar
+0 forum 4

Dear All, I am reading Generics, below method is confusing. It clearly mentioned in the Method parameter that it should accept only List. But when i give ArrayList as Argument it compiles. It should be only List right? eventhough Arraylist is an implementaion class. below is the code PLease explain. public class Quiz extends StringCheck { public Quiz() { // TODO Auto-generated constructor stub } public static void main(String[] args) { // TODO Auto-generated method stub ArrayList<Number> input =null; List<Number> output = null; output = process(input); } static <E extends Number> List<E> process(List<E> nums){ return nums; } } ** Here …

Member Avatar
Member Avatar
+0 forum 6

# Introduction # The subject of this tutorial is a bit more advanced than the subjects I have tackled in the past, but I hope this will find some interested readers. From time to time in C++, programmers find themselves torn apart between using a *Generic Programming* style which primarily involves the use of templates and compile-time mechanisms (e.g., STL), and using a *Object-Oriented Programming* style that often favors inheritance and run-time dispatching mechanisms (e.g., Qt). As it is so often the case, there is no obvious "winner", i.e., there is no paradigm that should always be preferred, even within …

Member Avatar
+2 forum 0

Hello, I have a difficulty with changing interface from ordinary one to generic one. Could you suggest me how I can achieve this goal, please? This is the way how I initialize API, based on user's choice from configuration which implementation of interface should be chosen: /// MyServiceApplication.MyServiceApplication.cs GeneralSystemAPI.Initialize(); This is code behind Initialize(): /// MyServiceApplication.GeneralSystemAPI.cs namespace MyServiceApplication { internal static class GeneralSystemAPI { internal static void Initialize() { //... CompanyAPI = FirstSystemAPI.Tools.GetCompanyAPI(); } internal static ICompanyAPI CompanyAPI {get; private set;} internal static void Destroy() { CompanyAPI = null; } } } And code behind GetCompanyAPI() for given implementation of …

Member Avatar
Member Avatar
+0 forum 2

Hello, I have a list that holds transactions. Currently I'm trying to write it to the console and have each transaction numbered with the transaction amount included beside it. I currently have code that produces something like Transaction #1: $400 Transaction #1: $400 Transaction #2: $599.99 Transaction #2: $599.99 How do I stop this? Obviously my code is wrong, here is what I have that's writing to console: foreach(decimal transaction in transactions) { for(decimal i=1; i<=transactions.Count; i++) { Console.WriteLine("Transaction #{0}: ${1}", i, transaction); } } If I need to post my whole program I can, but this is where it's …

Member Avatar
Member Avatar
+0 forum 5

Hey! Im doing a project, where i have to manage a bunch of different appliences. I´ve made a custom generic collection class that has a few different search methods. Now the collection class has to hold all of the different appliances (so they all inherits from the same superclass: Appliance). I can't see how the search methods can return anything but an object of the superclass, so when they return that i would like to be able to cast it to the actual appliance. The only way i can see how that is possible is to make an if-else chain …

Member Avatar
Member Avatar
+0 forum 5

Hello! I'm trying to fill a Crystal Reports in a generic way. This is because I don't have direct access to the database, I just call a service that returns a DataTable. I'm no expert in C# or Crystal Reports, is there any way to fill a Crystal report without knowing the columns I'm receiving? This is what I've tried so far: dt = new DataTable(); dt = getData(); var rpt = new ReportDocument(); rpt.Load(@"CrystalReport1.rpt"); rpt.SetDataSource(dt); crystalReportViewer1.ReportSource = rpt; var paramFields = new ParameterFields(); var paramField = new ParameterField {Name = "col1"}; var paramDiscreteValue = new ParameterDiscreteValue {Value = "Descripcion"}; …

Member Avatar
+0 forum 0

Hello, I have written a C# class for BinarySearchTree <T> where T is generic type, which creates a binary serach tree, returns true/false if it is empty, gives leftsubtree, rightsubtree, prints nodes. I want to write a search method, int search (T element), which will search the element if it already exists in the tree. For this I need to compare the element, with elements in the binary search tree. It is easy to do if elements are of specific type but for wrtiting a generic class, how do I compare two objects of type T, which is not known. …

Member Avatar
Member Avatar
+0 forum 5

Hello my fellow Daniwebers! I am having some problems wrapping my head around the task sorting a List(Of CustomType) I have a list containing a custom class. The class contains Two DateTime objects, Start and End. I am trying to sort the list descending so that the shortest timespan will be on the bottom of the list. I am unsure how to write the function that returns the value to sort. I have read Microsoft's documentation [here](http://msdn.microsoft.com/en-us/library/w56d4y5z.aspx) and, as all ways, I am more confused after reading it than I was before I began. This is what I have deducted …

Member Avatar
Member Avatar
+0 forum 2

Hi everyone, I have a project that creates a Train that pulls Boxcars. The boxcar is supposed to be generic type and have attributes such as load that adds only a specific type of object to the boxcar. The train is supposed to pull all boxcars created. I have written the following code but I get this error `The method load(capture#1-of ?) in the type Boxcar<capture#1-of ?> is not applicable for the arguments (Person)` package proj5; import java.util.ArrayList; import java.util.List; import java.util.Collections; public class Boxcar<T extends Comparable<T>> { private List<T> boxcar; private int maxItems; private int boxcarID; public Boxcar(){ boxcar …

Member Avatar
Member Avatar
+0 forum 2

Ok guys i have a few questions about implementing a gneric hash table using linear probing. Ok first, i need to make an entry class Entry<K,V> then An Entry <K,V> table array but since its gneric must initiatied elsewhere my question is how does the class entry work , from what i understand it will be like some sort of node with 2 fields of type K and V but i dont know how i will insert using entry then entering it in the table. This is what i have written so far. Am having trouble understanding it correctly, and …

Member Avatar
Member Avatar
+0 forum 5

List<? extends Integer> list = new ArrayList<Integer>(); for (Integer element : list) { System.out.println(element); List<? super Integer> list = new ArrayList<Integer>(); for (Integer element : list) { System.out.println(element); For the first three lines as Case 1 using extends it compiles fine. But for Case 2 of next three lines, it says incompatible types. Found Object, required Integer. My confusion is *? extends Integer* being **anything that is an Integer or sub of it** works. But why in Case 2 where *? super Integer* means **anything that is an Integer or a superclass of Integer** doesn't work when it's elements ar …

Member Avatar
Member Avatar
+0 forum 7

Hello I am a new to C++ and have some questions. I have two classes called Point and Square like this: [CODE] class Point { int x, y; public: int getx() const { return x; } int gety() const { return y; } Point(int a, int b) { x = a; y = b; } }; class Square { public: int x, y, length, width; SquareSpec(){return x, y, length, width;} Square(Point, int, int); }; Square::Square(Point A, int lngt, int wdth){ length = lngt; width = wdth; x = A.getx(); y = A.gety(); } [/CODE] Now the thing is that somehow …

Member Avatar
Member Avatar
+0 forum 14

I am trying to write a somewhat generic class for calculating rolling averages. It's generic in the sense that it needs to support all numeric datatypes (int, double, short and long). I'm a bit of a noobie to VB.Net and have run into a problem: [code] Public Class RollingAverage(Of T) Private _Values As List(Of T) Private _RollCountMax As Long Private _RollingTotal As T Public Sub New(Optional ByVal argRollCountMax As Long = 15) _RollCountMax = argRollCountMax Dim dataTest As T If (Not ((TypeOf (dataTest) Is Integer) Or (TypeOf (dataTest) Is Double) Or (TypeOf (dataTest) Is Short) Or (TypeOf (dataTest) Is Long))) …

Member Avatar
Member Avatar
+0 forum 1

I'm new to generic programming and I just cant figure out what is wrong in this . The program is supposed to make a linked list using class. I have used 2 classes so that a single object of class LL can be used to manipulate a linked list . I want the program to work for both integers and characters . When I try without the generic part , the code is working perfectly ! Somebody please help me ! My exam is tomorrow!! [CODE]#include<iostream> #include<stdlib.h> using namespace std; template<class T> class node { T data; node * link; …

Member Avatar
Member Avatar
+0 forum 2

I am developing a project with wcf . I need to develop a wcf service that will take data from database. I should write it in WCF custom data provider. I can do it with wcf linq and webService with EF. But I can not understand the example of Custom data provider with WCF.[URL="http://msdn.microsoft.com/en-us/library/ee960143.aspx"]http://msdn.microsoft.com/en-us/library/ee960143.aspx[/URL] Can anyone send me an easy example of wcf custom data provider. My mail is : <removed>

Member Avatar
Member Avatar
+0 forum 2

when uploading an image to the website i get the following error message: [CODE] Server Error in '/' Application. A generic error occurred in GDI+. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+. Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace: …

Member Avatar
Member Avatar
+0 forum 1

Hi All, I am new to XML,XSLT. I have been assigned to task of Generating HTML pages based on the XML file & the condition is No Hardcoding of Nodes and other details. My XML file is of the below struct: Node inside Nodes , and those nodes would contain any number of attribuites or elements. Now i need to knw , is there any Generic XSLT Algorithm to can do the above job and render the HTML page in the form of Navigation Tabs? Please advice...

Member Avatar
Member Avatar
+0 forum 7

The past few days I've posted some sorting routines customized to the tasks they were required to solve. Since I have a bunch of different sorting routines already coded, I decided to post them. Please note that some of these sorts are fast, but not a single one is as fast as the built in Array.Sort due to these using managed code while I suspect Array.Sort uses pointers and unmanaged code. The snippet above is the base class I use for all the sort routines to ensure that they are interchangeable. All the routines are generic sorts and will sort …

Member Avatar
Member Avatar
+3 forum 12

Consider the following code : [CODE]class R2<E> { E a; E get() { return a; } void set(E a) { this.a=a; } } class R3 { void doit(R2 a) // (1) { a.set(new Integer(5)); } }[/CODE] When I compile the file containing class R3, it rightly gives an unchecked warning because the compiler can't know for sure what was the element type of a (if any) i.e its a raw type. But if we replace (1) with : [CODE]void doit(R2<?> a)[/CODE] In this case, the compiler complains. My question is that the wildcard ? denotes all types, so it should …

Member Avatar
Member Avatar
+0 forum 5

Consider the following code : [CODE]class R2<E> { E a; E get() { return a; } void set(E a) { this.a=a; } public static void main(String aa[]) { R2 nn1=new R2<Integer>(); nn1.set("hello"); (1) //String r=nn1.get(); //Integer t=nn1.get(); } }[/CODE] In line (1), an unchecked warning is given as the compiler is not sure as to the generic type of nn1 (its raw type). But what I can't understand is that when the program is run, why is no exception thrown at line (1). What is E once the program has been compiled ?

Member Avatar
Member Avatar
+0 forum 7

Hey y'all, I was just curious about which idiom you prefer or use very often.. and why? Please vote on the poll! I understand that there are a lot of choices but you can vote for multiples, but try to pick only the ones you think are the best, or most useful, or most elegant to use, i.e., the ones you value most and/or recommend the most. - Resource Allocation Is Initialization - Non-copyable - Factory Functions - PImpl (Cheshire Cat) - Singleton - Lazy construction or evaluation - Type Traits - Smart Pointers - Curiously Recurring Template Pattern - …

Member Avatar
Member Avatar
+0 forum 3

The End.