Re: parametize the "is" keyword

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hi,

You can use the typeof,
something like this

private void foo(Type arg)
{
foreach (Control uc in _displayPanel.Controls)
{
if (typeof(uc) is arg)
uc.Visible = true;
else
uc.Visible = false;
}
}

And you can use it:

Type theType = typeof(bar);
foo(theType);

_____________________________
http://elblogdehoracio.blogspot.com

On 30 ene, 17:42, newcome...@xxxxxxxxx wrote:
Hi,
I understand how to use the "is" keyword straight forward.
like: if (obj is MyClass1)

However, I would like to parametize the "is"'s argument. Basically, I
would to replace MyClass1 with an argument. Here is an example:

private void foo(WhatType arg)
{
foreach (Control uc in _displayPanel.Controls)
{
if (uc is arg)
uc.Visible = true;
else
uc.Visible = false;
}
}

And call foo like...

foo(MyClass1);

My trouble is, I don't know what is the "arg"'s type? i.e. what
should "WhatType" be?
Is this is even possible?
Thanks for any pointer.
Minh (MCP)

.



Relevant Pages

  • Re: parametize the "is" keyword
    ... foreach (Control uc in _displayPanel.Controls) ... private void foo(WhatType arg) ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How do I fetch textbox value from dynamically created textbox
    ... you indicate the compiler that you know that the Control ... referenced by 'c' is a TextBox and not any other kind of control. ... > private void DCP_Init ... > foreach { ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: each control on a form
    ... foreach ... That's because controls on your form can be container controls themselves ... (the tab control is a container control, ... private void ClearDatabinding() ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Linq question on foreach
    ... foreach (string arg in args) ... I remember some in the group said, Linq will replace ... Linq can also sort and group your data, which is annoying to code manually into a loop or set of loops. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: when CurrentPrincipal is set in async call back, NET 2.0 loses CurrentPrincipal
    ... I have a custom Principal class implement IPrincipal interface. ... protected delegate object AsynchronousCall; ... private void okButton_Click ... protected override void OnAsynchronousCallEnd(object arg) ...
    (microsoft.public.dotnet.framework)