我正在製作一個控制檯應用程序,並且我想將Console.foregroundcolor代碼轉換爲布爾值,以便如果該值爲true,則文本顏色將爲綠色,如果爲false,則爲紅色。 謝謝!VB.NET Console.foregroundcolor as boolean?
0
A
回答
0
簡單地使一個變量和一個if語句將幫助你在這裏,因爲你沒有指定什麼它我會做一個例子:
Dim False As String = console.foregroundcolor = consolecolor.Red
Dim True As String = console.foregroundcolor = consolecolor.Green
然後做你的編碼四周,當談到是否需要將其剛剛要麼驗證的時刻做出:
驗證=假
OR
驗證=真
然後執行以下「如果」語句:「這是真的」
If Verification = True
True (To change the text colour)
Console.Writeline("This is True!")
ElseIf Verification = False
False (To change the text colour)
Console.Writeline("This is False!")
EndIf
,這樣就會將顯示綠色的文字與書面或紅色文字,「這是假的!」書面。
0
另一種方法是使用擴展方法。
Module ExtensionMethods
<Runtime.CompilerServices.Extension>
Public Function ToColor(ByRef b As Boolean) As System.ConsoleColor
If b Then
Return ConsoleColor.Green
Else
Return ConsoleColor.Red
End If
End Function
End Module
然後,你可以調用.ToColor()
您布爾
Dim myBool As Boolean = True
Console.ForegroundColor = myBool.ToColor
Console.WriteLine("This is green")
myBool = False
Console.ForegroundColor = myBool.ToColor
Console.WriteLine("This is Red")
Console.ForegroundColor = ConsoleColor.White
相關問題
- 1. sampleVariable As Boolean = My.settings.sampleSettings(boolean dataType)does not work
- 2. Android的display display boolean from Retrofit as false ALWAYS
- 3. VB.NET相當於C#「As」
- 4. VB.NET Dim mySingle As Single =「」運行時錯誤
- 5. 從VB.NET上傳到AS/400的FTP
- 6. volatile boolean
- 7. 方括號[]的使用方式的差異「As String」和「As [String]」?
- 8. recyclerview的setLayoutFrozen(boolean)和setHasFixedSize(boolean)目的
- 9. Java中boolean和Boolean有什麼區別?
- 10. 轉換爲Boolean
- 11. boolean algebra article/book
- 12. PHP boolean TRUE/FALSE?
- 13. VARCHAR(1)vs BOOLEAN
- 14. XPath boolean'或'
- 15. inverse boolean Navision
- 16. Wicket boolean model
- 17. C++ And Or Boolean
- 18. JSON golang boolean omitempty
- 19. JavaScript Boolean值,
- 20. DirectCast(False,Nullable(Of Boolean))錯誤
- 21. 將Func(Of Type,Boolean)轉換爲表達式(Of Func(Of Type,Boolean))?
- 22. 爲JavaScript Boolean問題
- 23. 行爲差異Dim oDialog1 as Dialog1 = New Dialog1 VS Dim oDialog1 as Dialog1 = Dialog1
- 24. MySQL匹配 - 在BOOLEAN模式?
- 25. SQL錯誤AS AS
- 26. c if或elseif boolean
- 27. AS3到Java(boolean?int:int)
- 28. Boolean.FALSE或new Boolean(false)?
- 29. setBorderPainted(boolean)不工作
- 30. Object == null vs boolean == false
'Console.foregroundcolor代碼爲boolean'你不能這樣做...你可能想要做的就是有一個布爾標誌來確定'Console.Foregroundcolor' – Ian
你在找什麼是'if'語句。 https://msdn.microsoft.com/en-us/library/752y8abs.aspx –