Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# check for exact type [duplicate]

Tags:

c#

types

I want to check the type of an object. I only want to return true if the type is exact the same. Inherited classes should return false.

eg:

class A {} class B : A {}  B b = new B();  // The next line will return true,  // but I am looking for an expression that returns false here if(b is A)  
like image 224
Tarscher Avatar asked Jan 29 '10 16:01

Tarscher


People also ask

What do you mean by C?

C is a structured, procedural programming language that has been widely used both for operating systems and applications and that has had a wide following in the academic community. Many versions of UNIX-based operating systems are written in C.

Why is CA procedural language?

C is an imperative procedural language supporting structured programming, lexical variable scope, and recursion, with a static type system. It was designed to be compiled to provide low-level access to memory and language constructs that map efficiently to machine instructions, all with minimal runtime support.

Why is C language used?

The C programming language is the recommended language for creating embedded system drivers and applications. The availability of machine-level hardware APIs, as well as the presence of C compilers, dynamic memory allocation, and deterministic resource consumption, make this language the most popular.

Why is C called a mid level programming language?

C has the features of both assembly level languages i.e low-level languages and higher level languages. So that's why C is generally called as a middle-level Language. The user uses C language for writing an operating system and generates menu driven customer billing system.


1 Answers

b.GetType() == typeof(A) 
like image 149
ChaosPandion Avatar answered Sep 20 '22 07:09

ChaosPandion