Click here to Skip to main content
15,897,187 members
Home / Discussions / C#
   

C#

 
AnswerRe: SQL Connection in Visual Studio Pin
Eddy Vluggen24-Apr-20 12:40
professionalEddy Vluggen24-Apr-20 12:40 
AnswerRe: SQL Connection in Visual Studio Pin
Matt Slay24-Apr-20 16:28
Matt Slay24-Apr-20 16:28 
AnswerRe: SQL Connection in Visual Studio Pin
OriginalGriff24-Apr-20 20:09
mveOriginalGriff24-Apr-20 20:09 
AnswerRe: SQL Connection in Visual Studio Pin
Gerry Schmitz25-Apr-20 11:46
mveGerry Schmitz25-Apr-20 11:46 
Questioncasting from interface instance back to generic instance ? Pin
BillWoodruff24-Apr-20 1:11
professionalBillWoodruff24-Apr-20 1:11 
GeneralRe: casting from interface instance back to generic instance ? Pin
harold aptroot24-Apr-20 1:29
harold aptroot24-Apr-20 1:29 
GeneralRe: casting from interface instance back to generic instance ? Pin
BillWoodruff24-Apr-20 2:41
professionalBillWoodruff24-Apr-20 2:41 
GeneralRe: casting from interface instance back to generic instance ? Pin
Richard Deeming24-Apr-20 3:26
mveRichard Deeming24-Apr-20 3:26 
The problem is that you don't know at compile-time what the run-time type of the instance will be.

As Harold said, there isn't a compile-time type you can use which would give you access to the properties or methods of the run-time type.

Consider:
C#
public abstract class Being
{
    public string Name { get; set; }
}

public class Dog : Being
{
    public void Bark() { ... }
}

public class Human : Being
{
    public void ComposeMusic() { ... }
}

List<Being> beings = LoadBeings();
Being aBeing = beings[0];
Type beingType = aBeing.GetType();

{ What could possibly go here? } myBeing = BeingAsType(aBeing, beingType);

myBeing.{ Which method could you call here? }();

Perhaps the visitor pattern might help you?



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

GeneralRe: casting from interface instance back to generic instance ? Pin
BillWoodruff24-Apr-20 4:52
professionalBillWoodruff24-Apr-20 4:52 
GeneralRe: casting from interface instance back to generic instance ? Pin
Richard Deeming24-Apr-20 4:59
mveRichard Deeming24-Apr-20 4:59 
AnswerRe: casting from interface instance back to generic instance ? Pin
jschell26-Apr-20 9:59
jschell26-Apr-20 9:59 
AnswerMessage Closed Pin
23-Apr-20 2:41
Corrie Lang23-Apr-20 2:41 
GeneralRe: During Pin
OriginalGriff23-Apr-20 3:15
mveOriginalGriff23-Apr-20 3:15 
QuestionRefreshing data on a parent form at child close Pin
Uranium-23521-Apr-20 20:24
Uranium-23521-Apr-20 20:24 
AnswerRe: Refreshing data on a parent form at child close Pin
OriginalGriff21-Apr-20 21:44
mveOriginalGriff21-Apr-20 21:44 
GeneralRe: Refreshing data on a parent form at child close Pin
Uranium-23521-Apr-20 22:48
Uranium-23521-Apr-20 22:48 
GeneralRe: Refreshing data on a parent form at child close Pin
OriginalGriff21-Apr-20 23:04
mveOriginalGriff21-Apr-20 23:04 
GeneralRe: Refreshing data on a parent form at child close Pin
Uranium-23522-Apr-20 23:27
Uranium-23522-Apr-20 23:27 
GeneralRe: Refreshing data on a parent form at child close Pin
OriginalGriff23-Apr-20 0:09
mveOriginalGriff23-Apr-20 0:09 
GeneralRe: Refreshing data on a parent form at child close Pin
Uranium-23523-Apr-20 10:46
Uranium-23523-Apr-20 10:46 
GeneralRe: Refreshing data on a parent form at child close Pin
OriginalGriff23-Apr-20 11:06
mveOriginalGriff23-Apr-20 11:06 
GeneralRe: Refreshing data on a parent form at child close Pin
Uranium-23524-Apr-20 17:53
Uranium-23524-Apr-20 17:53 
GeneralRe: Refreshing data on a parent form at child close Pin
OriginalGriff24-Apr-20 20:08
mveOriginalGriff24-Apr-20 20:08 
GeneralRe: Refreshing data on a parent form at child close Pin
Uranium-23525-Apr-20 19:42
Uranium-23525-Apr-20 19:42 
AnswerRe: Refreshing data on a parent form at child close Pin
#realJSOP22-Apr-20 7:15
professional#realJSOP22-Apr-20 7:15 

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.