Click here to Skip to main content
15,887,214 members
Home / Discussions / C#
   

C#

 
GeneralRe: GetAsyncKeyState in diffrent languages Pin
Luc Pattyn28-Jun-12 8:39
sitebuilderLuc Pattyn28-Jun-12 8:39 
GeneralRe: GetAsyncKeyState in diffrent languages Pin
Eddy Vluggen28-Jun-12 8:55
professionalEddy Vluggen28-Jun-12 8:55 
GeneralRe: GetAsyncKeyState in diffrent languages Pin
a.fatemeh28-Jun-12 8:44
a.fatemeh28-Jun-12 8:44 
GeneralRe: GetAsyncKeyState in diffrent languages Pin
Eddy Vluggen28-Jun-12 8:59
professionalEddy Vluggen28-Jun-12 8:59 
GeneralRe: GetAsyncKeyState in diffrent languages Pin
a.fatemeh28-Jun-12 9:31
a.fatemeh28-Jun-12 9:31 
GeneralRe: GetAsyncKeyState in diffrent languages Pin
Eddy Vluggen29-Jun-12 0:36
professionalEddy Vluggen29-Jun-12 0:36 
GeneralRe: GetAsyncKeyState in diffrent languages Pin
a.fatemeh29-Jun-12 4:23
a.fatemeh29-Jun-12 4:23 
QuestionGeneric method in generic method Pin
Mc_Topaz28-Jun-12 6:39
Mc_Topaz28-Jun-12 6:39 
I'm developing a Windows phone app with the SQLite SDK. I have reach a point where I want to call a generic within a generic method which the compiler cannot agree to use.

Here is a short version of the code which gives the same compile error as my application for my Windows phone.

XML
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Friend[] friends = Foo<Friend>();
        }

        static T[] Foo<T>()
        {
            var obj = Bar<T>(); // <--- Compile error
            T[] array = obj.ToArray();
            return array;
        }

        // Method from a SDK. Cannot edit this method
        static IEnumerable<T> Bar<T>() where T : new()
        {
            for (int i = 0; i < 10; i++)
            {
                var obj = new T();
                yield return obj;
            }
        }
    }

    class Friend
    {
        public Friend()
        {
        }

        public string name;
    }
}


Let me explain the code:

There are two methods here.
My method: Foo<t>()
The SDK's method: Bar<t>()

I cannot change the SDK's method and have to use it as it is.

In Foo<t>() I get the compile error when I try to call the Bar<t>() method.

The compile error is:
"'T' must be a non-abstract type with a public parameterless constructor in order to use it as parameter 'T' in the generic type or method 'ConsoleApplication1.Program.Bar<t>()'"

If you paste in the code above in a console application, you'll have the same compile error.

Is there any way I can change the Foo<t>() method so it work with the Bar<t>() method and is easy to call in the Main() method?

The SDK method I'm referring to is:
inside the SQLiteClient file in the SQLiteCommand class and is called: "IEnumerable<t> ExecuteQuery<t>()".
You'll need the SQLite SDK for Windows phone to access it.
AnswerRe: Generic method in generic method Pin
PIEBALDconsult28-Jun-12 6:45
mvePIEBALDconsult28-Jun-12 6:45 
GeneralRe: Generic method in generic method Pin
Mc_Topaz28-Jun-12 12:07
Mc_Topaz28-Jun-12 12:07 
AnswerRe: Generic method in generic method Pin
Luc Pattyn28-Jun-12 6:49
sitebuilderLuc Pattyn28-Jun-12 6:49 
GeneralRe: Generic method in generic method Pin
Mc_Topaz28-Jun-12 12:08
Mc_Topaz28-Jun-12 12:08 
QuestionC:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0 not seen by visual studio Pin
AstroBod42728-Jun-12 5:16
AstroBod42728-Jun-12 5:16 
AnswerRe: C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0 not seen by visual studio Pin
Abhinav S28-Jun-12 6:33
Abhinav S28-Jun-12 6:33 
GeneralLooking for help with double clicking on a line of text in a text box Pin
turbosupramk328-Jun-12 4:18
turbosupramk328-Jun-12 4:18 
AnswerRe: Looking for help with double clicking on a line of text in a text box Pin
Eddy Vluggen28-Jun-12 4:47
professionalEddy Vluggen28-Jun-12 4:47 
GeneralRe: Looking for help with double clicking on a line of text in a text box Pin
Luc Pattyn28-Jun-12 4:59
sitebuilderLuc Pattyn28-Jun-12 4:59 
GeneralRe: Looking for help with double clicking on a line of text in a text box Pin
Pete O'Hanlon28-Jun-12 5:10
mvePete O'Hanlon28-Jun-12 5:10 
GeneralRe: Looking for help with double clicking on a line of text in a text box Pin
turbosupramk328-Jun-12 7:21
turbosupramk328-Jun-12 7:21 
GeneralRe: Looking for help with double clicking on a line of text in a text box Pin
Pete O'Hanlon28-Jun-12 8:18
mvePete O'Hanlon28-Jun-12 8:18 
GeneralRe: Looking for help with double clicking on a line of text in a text box Pin
turbosupramk328-Jun-12 8:30
turbosupramk328-Jun-12 8:30 
GeneralRe: Looking for help with double clicking on a line of text in a text box Pin
turbosupramk328-Jun-12 5:34
turbosupramk328-Jun-12 5:34 
GeneralRe: Looking for help with double clicking on a line of text in a text box Pin
Pete O'Hanlon28-Jun-12 5:38
mvePete O'Hanlon28-Jun-12 5:38 
QuestionCorrect way of doing installer in Windows.... Pin
glennPattonWork328-Jun-12 3:58
professionalglennPattonWork328-Jun-12 3:58 
AnswerRe: Correct way of doing installer in Windows.... Pin
Pete O'Hanlon28-Jun-12 4:13
mvePete O'Hanlon28-Jun-12 4:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.