How can I use a generic indifferently in one of the generic's member functions?

I'm curious about the following situation:
I'd like to access another generic's private member in a constructor. How can I do that irrespective of the generic's actual type?
Here's a sample of what I'm trying to accomplish:
public class C<T>
private int _hdc;
// private T _someMember;
public C()
this._hdc = CreateHdc();
public C(C src) // what would be the correct signature here to be able to run the assignment in ::f() below?
this._hdc = src.hdc;
function f()
C<int> a = new C();
C<string> b = new C(a); // how can I get this to work?
Do I need to create a non-generic base class to be able to use a differently typed object in the construtor? Or is there some C# construct that will allow me to define an untyped generic parameter and only use the untyped members from that parameter?
Still people out there alive using the keyboard?
Working with SQL Server/Office/Windows and their poor keyboard support they seem extinct...

>>I'd like to access another generic's private member in a constructor.
You cannot access a class' private member from any other class directly. You could expose a private field through a property or define a public method (or constructor) that sets the private field though.
>>How can I do that irrespective of the generic's actual type?
You cannot assign a string field to an int value or the other way around without converting the value to a string/int first.
A C<int> object always has an int field - the generic class is not really a type of its own but rather a "blue-print" or a template for a type - and you cannot assign this one to a string value.
Since the C<string> class Always has a string field you need to convert the int value of the C<int> object to a string before you can ever assign the string field to this value:
C<int> a = new C();
C<string> b = new C(a.ToString());
C<int> and C<string> are two completely different types. They are not related to each other and as mentioned you cannot assing a string field to an int value.
>>Or is there some C# construct that will allow me to define an untyped generic parameter and only use the untyped members from that parameter?
There is no such thing as "an unyped generic parameter" in C#. T always refers to a type and you must specify the type when you create an instance of the generic type.
Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question.

Similar Messages

  • How can I use two single-dimensional arrays-one for the titles and array

    I want to Use two single-dimensional arrays-one for the titles and one for the ID
    Could everyone help me how can i write the code for it?
    Flower
    public class Video
    public static void main(String[] args) throws Exception
    int[][] ID =
    { {145,147,148},
    {146,149, 150} };
    String[][] Titles=
    { {"Barney","True Grit","The night before Christmas"},
    {"Lalla", "Jacke Chan", "Metal"} };
    int x, y;
    int r, c;
    System.out.println("List before Sort");
    for(c =0; c< 3; ++c)
    for(r=0; r< 3; ++ r)
    System.out.println("ID:" + ID[c][r]+ "\tTitle: " + Titles[c][r]);
    System.out.println("\nAfter Sort:");
    for(c =0; c< 3; ++c)
    for(r=0; r< 3; ++ r)
    System.out.println("ID:" + ID[c][r]+ "\tTitle: " + Titles[c][r]);

    This is one of the most bizarre questions I have seen here:
    public class Video
    public static void main(String[] args) throws Exception
    int[] ID = {145,147,148, 146,149, 150};
    String[] Titles= {"Barney","True Grit","The night before Christmas", "Lalla", "Jacke Chan", "Metal"};
    System.out.println("List before Sort");
    for(int i = 0; i < Titles.length; i++)
       System.out.println("ID:" + ID[i]+ "\tTitle: " + Titles);
    System.out.println("\nAfter Sort:");
    for(int i = 0; c < Titles.length; i++)
    System.out.println("ID:" + ID[i]+ "\tTitle: " + Titles[i]);
    Generally you don't use prefix (++c) operators in you for loop. Use postfix (c++).
    Prefix means that it will increment the variable before the loop body is executed. Postfix will cause it to increment after.

  • How can I Publish to a Folder just one of the several websites I have created using iWeb?

    How can I Publish to a Folder just one of the several websites I have created using iWeb?
    it drives me nuts having to emove all the other websites when I want to upload one. 
    Sparrow

    For iWeb, I like to do only one site per domain file.  I move domain files out of the Application Support folder and place them inside project or client folders, or in DropBox. Once you duplicate a domain file and begin customizing it, it will load and behave as a separate project/site.
    I publish each iWeb domain/project direct to a server via FTP. Sometime I publish to a folder, then upload via FTP manually.
    iWeb is a remarkable tool, especially when you work from scratch with blank tamplates
    Here are a few of my iWeb sites:
    http://www.newcovenant.org
    http://www.visionmultimedia.org
    http://www.visioncomsolutions.com

  • How can I use different iTunes accounts on one iPad?

    How can I use different iTunes accounts on one iPad?

    You can't, well not easily anyway.  The iPad is not meant as a multi account device. 
    You can Sign Out of your iTunes account in Settings->iTunes and App Stores->Apple ID->Sign Out
    However if you sign in with another ID and then download past purchases with it you will lock out the previous ID for 90 days. Which means it will not be able to be used on the iPad for 90 days. 

  • How can someone use a stolen iphone? does erasing the phone (which I feel like I should do) make it easier for the thief to use the iphone?  If I don't erase it, it doesn't seem like anyone should be able to use the phone because of my password.

    how can someone use a stolen iphone? does erasing the phone (which I feel like I should do) make it easier for the thief to use the iphone?  If I don't erase it, it doesn't seem like anyone should be able to use the phone because of my password. Also, is it possible to retrieve anything that has been sent to the phone (i.e. text messages) since it was stolen through icloud? The "find my iphone" app says the device is offline but it rings when I call my number -- any idea how that would be the case? Thanks!!

    You have a password, so good move on your part.  Whether you erase it or the thief does, they still get to use the iPhone as theirs.  Which is more important (pick one), protecting your data or punishing the thief?
    Ringing occurs at the carrier.  Chances are you're going to voicemail after only two or three rings.  If you have an iCloud backup also a good move.  Re-read my question in the first paragraph.

  • How can I use FaceTime between 2 I-Pads sharing the same email account

    How can I use FaceTime between 2 I-Pads sharing the same email address

    Cstearns-
    I only have one iPad, but was able to add myself to the list of Favorites.  When I tried to call, I was not available!
    You should also take a look at the Skype App for iPhone.  It works on the iPad, where you can choose 2X to expand the display.  I haven't tried to add myself to Skype, but have been able to have it connected on both my computer and the iPad at the same time.
    You might also consider getting a second address from G-Mail, just for use with FaceTime.
    Fred

  • Living in Europe how can I use a gift card valid only on the U.S. iTunes Store

    Living in Europe how can I use a gift card valid only on the U.S. iTunes Store?

    Sorry...   iTunes Gift Cards are only Valid in Country of Issue.

  • How can I use a vector image to stretch with the backgrounds in Muse master pages?

    How can I use a vector image to stretch with the backgrounds in Muse master pages?

    Maybe there's a bug.  I think it's only showing it when it wants to because look:

  • So how can I use my iPhone or stream music on the ATV without having use of the computer?. I am limited I have wifi iPhone ATV and hd TV. My ATV has a setting for AirPlay as well. Please help :)

    So how can I use my iPhone or stream music on the ATV without having use of the computer?. I am limited I have wifi iPhone ATV and hd TV. My ATV has a setting for AirPlay as well. Please help :)

    Use AirPlay.

  • How can i use both Windows and Mac os at the same time on my iMac

    How can i use both Windows and Mac os at the same time on my iMac

    You can use Parallels desktop or VM Fusion to run both operating systems at the same time. Both programs work well, but I personally perfer VM Fusion.

  • Hi, how can i have a live chat with one of the people from apple so i they can help me with my problem?

    hi, how can i have a live chat with one of the people from apple so i they can help me with my problem?

    https://getsupport.apple.com/Issues.action

  • My gf is one of those ppl with the horrible habbit of downloading anything and everything the internet tells her she needs how can i use FF to better protect her from the various virus she downloads on a regular basise

    as i write this i have just restored my gf's computer back to default factory setings and cleaned the HD she has a horrible habbit of downloading anything and everything something tells her to download it her most recent actions caused her to dl a virus along with a prog called "flv tube" ive never heard of it but in less then 5 mins on google i found it to be common with viruses how can i use FF to prevent and or stop her from downloading all this crap so im not always having to fix it for her

    Public Fox: https://addons.mozilla.org/firefox/addon/3911
    Be aware that an extension can easily be bypassed by starting Firefox in [[Safe mode]] or by using the portable Firefox version.

  • HT2305 I PURCHASED AN ITUNES CARD FOR $50.00 IN THE USA WHILE I WAS ON VACATION  HOW CAN I USE THIS CARD WHILE I AM IN THE USA.    .......ELLIS

    I purchased an itunes card in the USA while on vacation for $50.00----how can I use the card while in the usa.....Ellis

    You will need to set up an account in the US iTunes Store to use that card, for which you will need a valid US mailing address. Note that the Terms of Use for the iTunes Store state that you will not attempt to use the US iTunes Store from any other country, so you will not be able to buy new items or re-download previously purchased ones from the US without violating those terms. So you may want to reconsider your purchase and perhaps return the iTunes card or sell it to someone who lives in the US.
    Regards.

  • Having updated to iOS7 how can I use a different Game Centre account than the one that is connected to my Apple ID?

    Having updated to iOS7, how can I use a more than one Game Centre? I have children linked to my Apple ID as they are too young to have thier own ID.

    Yes, you can certainly create a new Apple ID at appleid.apple.com (which will have to be associated with a different email address from your current ID) and then change the various settings and applications on one of your iPhones to use this new ID.

  • How can I use two differant iphones on one itunes

    I can i use two differant iphones on one itunes, and keep the content seperate?

    You can sync as many iphones/ipod/ipads as you like to one computer.
    Each is different and is recognized as such

Maybe you are looking for

  • No longer able to drag and drop songs into playlists on iPhone?

    How's it going, I had to reset my phone the other day and I was able to add a playlist to the iPhone, but now it wont let me add selected songs to the playlist on my iPhone, only sync it through the playlist on my iTunes. What happened?

  • Only 1 song downloaded from ipad to iphone

    I downloaded 5 songs from itunes using ipad.Only 1 of the songs automatically downloaded to iphone.Can I transfer the rest to iphone without connecting to pc and itunes?If so,how do  do it?I am new to iphone and ipad.Also,can I transfer photos from o

  • ITunes Library file corrupt or unreadable -- unable to be saved

    When I open itunes, I have to import my library everytime... and it says that the library file is corrupt or unreadable and cannot be saved. Can anyone else with this issue, please?

  • Turned on Itunes Match, now Itunes says my Ipad is over capacity

    So, today I turned on Itunes Match and let it run while I slept.  When I woke up, it was finished. Problem is, now my 64-gig Ipad is 49gig over capacity, according to Itunes... even though I use the "convert music to 128kpps AAC" option and it used t

  • What Kind of Music Can Be Found In Your Micro/Touch/Etc

    I'm sorry if this kind of post is discouraged seeing how this board is made for support and etc, but curiosity got the better of me.. As the title of the topic said.. what kind of music can be found in your MP3 player? As I'm on a search for some dec