Advertisement
stefanpu

Complex Ternary condition

Mar 2nd, 2013
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Numerics;
  6.  
  7. namespace ConsoleApplication1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             //First case
  14.             Console.WriteLine("first: null; second: \"aa\"");
  15.             string first = null;
  16.             string second = "aa";
  17.             string matrixNullMessage = first == null ? " first" + (second==null?" and second matrices ":" matrix ") :
  18.                 "" + (second==null?" second matrix ":"");
  19.            
  20.             string message = "The" + matrixNullMessage + "not initialised.";
  21.             Console.WriteLine(message + "\n");
  22.  
  23.             //Second case
  24.             Console.WriteLine("first: null; second: null");
  25.             first = null;
  26.             second = null;
  27.             matrixNullMessage = first == null ? " first" + (second == null ? " and second matrices " : " matrix ") :
  28.                 "" + (second == null ? " second matrix " : "");
  29.  
  30.             message = "The" + matrixNullMessage + "not initialised.";
  31.             Console.WriteLine(message+"\n");
  32.  
  33.             //Third case
  34.             Console.WriteLine("first: \"aa\"; second: null");
  35.             first = "aa";
  36.             second = null;
  37.             matrixNullMessage = first == null ? " first" + (second == null ? " and second matrices " : " matrix ") :
  38.                 "" + (second == null ? " second matrix " : "");
  39.  
  40.             message = "The" + matrixNullMessage + "not initialised.";
  41.             Console.WriteLine(message + "\n");
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement