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

C#

 
GeneralRe: how to check vaild email address? Pin
Richard Deeming29-Sep-14 1:42
mveRichard Deeming29-Sep-14 1:42 
AnswerRe: how to check vaild email address? Pin
jschell29-Sep-14 7:49
jschell29-Sep-14 7:49 
Questioninvoke method in derived classes vs. invoke method in base class: C# language question Pin
BillWoodruff27-Sep-14 21:56
professionalBillWoodruff27-Sep-14 21:56 
AnswerRe: invoke method in derived classes vs. invoke method in base class: C# language question Pin
Kornfeld Eliyahu Peter27-Sep-14 22:47
professionalKornfeld Eliyahu Peter27-Sep-14 22:47 
GeneralRe: invoke method in derived classes vs. invoke method in base class: C# language question Pin
BillWoodruff27-Sep-14 23:44
professionalBillWoodruff27-Sep-14 23:44 
AnswerRe: invoke method in derived classes vs. invoke method in base class: C# language question Pin
Kornfeld Eliyahu Peter27-Sep-14 23:55
professionalKornfeld Eliyahu Peter27-Sep-14 23:55 
GeneralRe: invoke method in derived classes vs. invoke method in base class: C# language question Pin
Richard Deeming29-Sep-14 1:40
mveRichard Deeming29-Sep-14 1:40 
AnswerRe: invoke method in derived classes vs. invoke method in base class: C# language question Pin
Kornfeld Eliyahu Peter29-Sep-14 2:06
professionalKornfeld Eliyahu Peter29-Sep-14 2:06 
Of course it is a callvirt! However C# always uses callvirt when calling instance methods! So other there is no difference between the two...
Take this code for instance:
C#
using System.Diagnostics;

namespace ConsoleApplication1
{
	class Program
	{
		static void Main ( string[ ] args )
		{
			BaseClass baseClass = new BaseClass( );
			DerivedClass1 derivedClass1 = new DerivedClass1( );
			DerivedClass2 derivedClass2 = new DerivedClass2( );

			invokeClassMethod( baseClass );
			invokeClassMethod( derivedClass1 );
			invokeClassMethod( derivedClass2 );

			//

			BaseClassD baseClassD = new BaseClassD( );
			DerivedClass1D derivedClass1D = new DerivedClass1D( );
			DerivedClass2D derivedClass2D = new DerivedClass2D( );

			invokeClassMethodD( baseClassD );
			invokeClassMethodD( derivedClass1D );
			invokeClassMethodD( derivedClass2D );
		}

		static private void invokeClassMethod ( BaseClass theClass )
		{
			theClass.ShowMe( );
		}

		static private void invokeClassMethodD ( BaseClassD theClass )
		{
			theClass.ShowMe( );
		}
	}

	public class BaseClass
	{
		public virtual void ShowMe ( )
		{
			Debug.WriteLine( "BaseClass" );
		}
	}

	public class DerivedClass1 : BaseClass
	{
		public override void ShowMe ( )
		{
			Debug.WriteLine( "DerivedClass1" );
		}
	}

	public class DerivedClass2 : BaseClass
	{
		public override void ShowMe ( )
		{
			Debug.WriteLine( "DerivedClass2" );
		}
	}

	public class BaseClassD
	{
		public void ShowMe ( )
		{
			Debug.WriteLine( "BaseClass" );
		}
	}

	public class DerivedClass1D : BaseClassD
	{
		public void ShowMe ( )
		{
			Debug.WriteLine( "DerivedClass1" );
		}
	}

	public class DerivedClass2D : BaseClassD
	{
		public void ShowMe ( )
		{
			Debug.WriteLine( "DerivedClass2" );
		}
	}
}

And see the IL code for the same:
C#
  1  .class private auto ansi beforefieldinit ConsoleApplication1.Program
  2  	extends [mscorlib]System.Object
  3  {
  4  	// Methods
  5  	.method private hidebysig static 
  6  		void Main (
  7  			string[] args
  8  		) cil managed 
  9  	{
 10  		// Method begins at RVA 0x2050
 11  		// Code size 84 (0x54)
 12  		.maxstack 1
 13  		.entrypoint
 14  		.locals init (
 15  			[0] class ConsoleApplication1.BaseClass baseClass,
 16  			[1] class ConsoleApplication1.DerivedClass1 derivedClass1,
 17  			[2] class ConsoleApplication1.DerivedClass2 derivedClass2,
 18  			[3] class ConsoleApplication1.BaseClassD baseClassD,
 19  			[4] class ConsoleApplication1.DerivedClass1D derivedClass1D,
 20  			[5] class ConsoleApplication1.DerivedClass2D derivedClass2D
 21  		)
 22  
 23  		IL_0000: nop
 24  		IL_0001: newobj instance void ConsoleApplication1.BaseClass::.ctor()
 25  		IL_0006: stloc.0
 26  		IL_0007: newobj instance void ConsoleApplication1.DerivedClass1::.ctor()
 27  		IL_000c: stloc.1
 28  		IL_000d: newobj instance void ConsoleApplication1.DerivedClass2::.ctor()
 29  		IL_0012: stloc.2
 30  		IL_0013: ldloc.0
 31  		IL_0014: call void ConsoleApplication1.Program::invokeClassMethod(class ConsoleApplication1.BaseClass)
 32  		IL_0019: nop
 33  		IL_001a: ldloc.1
 34  		IL_001b: call void ConsoleApplication1.Program::invokeClassMethod(class ConsoleApplication1.BaseClass)
 35  		IL_0020: nop
 36  		IL_0021: ldloc.2
 37  		IL_0022: call void ConsoleApplication1.Program::invokeClassMethod(class ConsoleApplication1.BaseClass)
 38  		IL_0027: nop
 39  		IL_0028: newobj instance void ConsoleApplication1.BaseClassD::.ctor()
 40  		IL_002d: stloc.3
 41  		IL_002e: newobj instance void ConsoleApplication1.DerivedClass1D::.ctor()
 42  		IL_0033: stloc.s derivedClass1D
 43  		IL_0035: newobj instance void ConsoleApplication1.DerivedClass2D::.ctor()
 44  		IL_003a: stloc.s derivedClass2D
 45  		IL_003c: ldloc.3
 46  		IL_003d: call void ConsoleApplication1.Program::invokeClassMethodD(class ConsoleApplication1.BaseClassD)
 47  		IL_0042: nop
 48  		IL_0043: ldloc.s derivedClass1D
 49  		IL_0045: call void ConsoleApplication1.Program::invokeClassMethodD(class ConsoleApplication1.BaseClassD)
 50  		IL_004a: nop
 51  		IL_004b: ldloc.s derivedClass2D
 52  		IL_004d: call void ConsoleApplication1.Program::invokeClassMethodD(class ConsoleApplication1.BaseClassD)
 53  		IL_0052: nop
 54  		IL_0053: ret
 55  	} // end of method Program::Main
 56  
 57  	.method private hidebysig static 
 58  		void invokeClassMethod (
 59  			class ConsoleApplication1.BaseClass theClass
 60  		) cil managed 
 61  	{
 62  		// Method begins at RVA 0x20b0
 63  		// Code size 9 (0x9)
 64  		.maxstack 8
 65  
 66  		IL_0000: nop
 67  		IL_0001: ldarg.0
 68  		IL_0002: callvirt instance void ConsoleApplication1.BaseClass::ShowMe()
 69  		IL_0007: nop
 70  		IL_0008: ret
 71  	} // end of method Program::invokeClassMethod
 72  
 73  	.method private hidebysig static 
 74  		void invokeClassMethodD (
 75  			class ConsoleApplication1.BaseClassD theClass
 76  		) cil managed 
 77  	{
 78  		// Method begins at RVA 0x20ba
 79  		// Code size 9 (0x9)
 80  		.maxstack 8
 81  
 82  		IL_0000: nop
 83  		IL_0001: ldarg.0
 84  		IL_0002: callvirt instance void ConsoleApplication1.BaseClassD::ShowMe()
 85  		IL_0007: nop
 86  		IL_0008: ret
 87  	} // end of method Program::invokeClassMethodD
 88  
 89  	.method public hidebysig specialname rtspecialname 
 90  		instance void .ctor () cil managed 
 91  	{
 92  		// Method begins at RVA 0x20c4
 93  		// Code size 7 (0x7)
 94  		.maxstack 8
 95  
 96  		IL_0000: ldarg.0
 97  		IL_0001: call instance void [mscorlib]System.Object::.ctor()
 98  		IL_0006: ret
 99  	} // end of method Program::.ctor
100  
101  } // end of class ConsoleApplication1.Program

See line 68 and 84 - both have callvirt event the second is not a virtual member...
I also found this...http://blogs.msdn.com/b/ericgu/archive/2008/07/02/why-does-c-always-use-callvirt.aspx[^]
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

Questionexecuting multiple sql select queries in ms access using c# Pin
nishadamit9027-Sep-14 21:32
nishadamit9027-Sep-14 21:32 
QuestionXSD question... Pin
SledgeHammer0126-Sep-14 15:41
SledgeHammer0126-Sep-14 15:41 
QuestionRe: XSD question... Pin
Richard MacCutchan26-Sep-14 21:37
mveRichard MacCutchan26-Sep-14 21:37 
QuestionRe: XSD question... Pin
George Jonsson27-Sep-14 3:55
professionalGeorge Jonsson27-Sep-14 3:55 
AnswerRe: XSD question... Pin
SledgeHammer0127-Sep-14 6:26
SledgeHammer0127-Sep-14 6:26 
AnswerRe: XSD question... Pin
George Jonsson27-Sep-14 13:21
professionalGeorge Jonsson27-Sep-14 13:21 
GeneralRe: XSD question... Pin
SledgeHammer0127-Sep-14 14:21
SledgeHammer0127-Sep-14 14:21 
GeneralRe: XSD question... Pin
George Jonsson27-Sep-14 15:13
professionalGeorge Jonsson27-Sep-14 15:13 
GeneralRe: XSD question... Pin
SledgeHammer0127-Sep-14 16:00
SledgeHammer0127-Sep-14 16:00 
GeneralRe: XSD question... Pin
George Jonsson27-Sep-14 20:21
professionalGeorge Jonsson27-Sep-14 20:21 
GeneralRe: XSD question... Pin
SledgeHammer0128-Sep-14 7:10
SledgeHammer0128-Sep-14 7:10 
QuestionRecommendations on VB.Net to C# code conversion tool Pin
Vipul Mehta26-Sep-14 8:31
Vipul Mehta26-Sep-14 8:31 
QuestionRe: Recommendations on VB.Net to C# code conversion tool Pin
Richard MacCutchan26-Sep-14 10:16
mveRichard MacCutchan26-Sep-14 10:16 
QuestionRe: Recommendations on VB.Net to C# code conversion tool Pin
Vipul Mehta26-Sep-14 10:23
Vipul Mehta26-Sep-14 10:23 
AnswerRe: Recommendations on VB.Net to C# code conversion tool Pin
Richard MacCutchan26-Sep-14 21:27
mveRichard MacCutchan26-Sep-14 21:27 
AnswerRe: Recommendations on VB.Net to C# code conversion tool Pin
Ravi Bhavnani28-Sep-14 4:17
professionalRavi Bhavnani28-Sep-14 4:17 
AnswerRe: Recommendations on VB.Net to C# code conversion tool Pin
Simon_Whale28-Sep-14 8:29
Simon_Whale28-Sep-14 8:29 

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.