[C #] is and,
Let's look at an example:
Public class User {} public class Group {} class Program {static void Main (string [] args) {Object oUser = new User (); Object user = (Group) oUser ;}}View Code
In this case, an error is reported (InvalidCastException). Due to the C # security mechanism, it will judge once. The conversion is invalid here.
Is to judge: is to judge whether the object Is the type you want (here, the User)
Class Program {static void Main (string [] args) {Object obj = new User (); if (obj is User) {User user = (User) obj ;}}}View Code
In this case, we make a judgment on the obj is User. As we have just said, the compiler will perform an operation like (User) obj (forced conversion, in this way, there is a consumption of performance. Let's take a look at.
AS operation: if the object is modified, it is converted. If not, null is returned.
Class Program {static void Main (string [] args) {Object obj = new User (); User user = obj as User; if (user = null) {// handle error //....}}}View Code
Note: individuals prefer to use As, which simplifies operations and improves performance. It is convenient to make a NULL judgment and directly handle such exceptions.
[C Language] Is there a function that can clear keys in the cache?
Fflush (stdin)
Clear standard input Cache
# Include "stdio. h"
Main ()
{
Char a, B;
Scanf ("% c", & );
// Fflush (stdin );
Scanf ("% c", & B );
Printf ("\ n % c", a, B );
}
You can try it. If there is no fflush (stdin), if you enter a string of characters "abcd", a = 'A', B = 'B'
If fflush (stdin) exists, after entering "abcd", the program continues to wait for the input, and then enters "efdfsd". The result is a = 'A', B = 'E'
What is the letter in c?
What letter?
What if it's a letter play? [It is a drama for H.
Or c in c? It means cosplay. c is the language cosplay.