What is the truth value of the types in C#?

Mati-as·2022년 12월 22일
post-thumbnail

Welcome in!

Have you heard of 'truth value'?


Obviously yes, if you were a programmer or studying programming.

My topic today is "what is the truth value" and what are the truth values of types in C#.

check this out to get the detail of the method. https://learn.microsoft.com/en-us/dotnet/api/system.convert.toboolean?view=net-7.0

what is the type? (C#)

To begin with, we need to talk about what the values are. As we've already seen that they mean a type is a kind of 'certain kind',me being a smartmouth unintentionally.

We can say that int,string,float,double are some of types.To put it another way,our putting a certain type upon a value(being called constructor.) means clarification of the named value.For example you'll probably have no way to notice that 123 is just the number to be used for calculating or another number to be used for just showing information like number of a bus._In this example, if you'd like to multiply 123 by two or whatever even by it self.You cannot use a string type of 123(in C#).Instead,you have to use int type of 123.

what is the truth value?

so let's turn to the truth value again. Let's check the definition of the truth value first;The value telling if an argument is true or false. so how can it tells if it's true or not?

the truth value example

It's quite simple but it has different rules from type to type.

Firstly,for int(;integer) is false when int is 0 otherwise it's true. For example, when an integer variable is -1,-2 is 'true' as well. don't be confused about this point.

Secondly,float and double has almost the same rule as int's if they are 0 or 0.1,0.001,,and so like. they are false. Otherwise, they are true.

Thridly, string one has "true" or "false". However, I'd like to warn you that, unlike int,float and double type, if a string is neither "true" or "false", your code is going to fall through by an exception error. It would be confusing if you're not familiar with string type, but I'm sure you would find it quite intuitive and easy when you get used to this type.

Lastly, Boolean type has the true or false in a literal way. It means Boolean has either literally true or false. Take note as well that if it's neither 'true' or 'not', you put another literal into boolean type, your code is going to fall through as well like the case of rule of 'string'.

the codes

using System;

bool b = Convert.ToBoolean(Console.ReadLine());

if (Convert.ToBoolean(b))//when string b is "true" **regardless of upper or lower case**
{
   
    Console.WriteLine(b.ToString());
}
else if(!Convert.ToBoolean(b))//when string b is "false" **regardless of upper or lower case **
{
    Console.WriteLine(b);
}

profile
plonker yet

6개의 댓글

comment-user-thumbnail
2023년 4월 4일

who need help improving their coding skills c necklace , daily game solve cross

답글 달기
comment-user-thumbnail
2024년 11월 29일

Impostor Rush Rocket Launcher will among us equip you for an incredible adventure!

답글 달기
comment-user-thumbnail
2025년 2월 10일

With its well-structured narrative Sprunki and cogent reasoning, the article captivates the reader's attention and leaves a lasting impression.

답글 달기
comment-user-thumbnail
2025년 5월 9일

Speed Stars features an engaging progression system, rewarding players for their achievements with in-game currency, which can be used to unlock new cars and upgrades, creating a sense of accomplishment after each race.

답글 달기
comment-user-thumbnail
2025년 6월 10일

Each level in wacky flip is a creative challenge, requiring dexterity and sometimes a little "crazy".

답글 달기
comment-user-thumbnail
2025년 8월 17일

The way you approach problems with patience and persistence is inspiring. Instead of getting frustrated, you break them https://bloodmoneyonline.com down into small, solvable tasks. It’s a reminder that no problem is too big if you approach it the right way.

답글 달기