what is the different between Null & Empty?! | Sololearn: Learn to code for FREE! (2024)

for example in C# we have string.IsNullOrEmpty()!! i wonder if both Null & Empty dont have value, so why they used like that?! Please explain this for me💙

1st Mar 2022, 5:43 AM

‎Mr.Kaveh

what is the different between Null & Empty?! | Sololearn: Learn to code for FREE! (1)

3 Answers

+ 3

‎Mr.Kaveh It is used like that because we want to check if the variable is null or empty. The variable will have garbage value if we don't assign it with nullFor example Input : str = null // initialize by null value String.IsNullOrEmpty(str) Output: True /*****************************/Input : str = String.Empty // initialize by empty value String.IsNullOrEmpty(str) Output: True/**==========*************/// We need to assign a variable either some value or null value// if we do not initialize a variable it will take some garbage value. Garbage value is the value which is already present in a memory location. As we know that there are many programs run on a computer. So who knows what value that particular memory location is holding.// So when we assign a variable to null then it simply means that the particular memory location has nothing in it ( no garbage )// Empty means 0 // Null means no existence of anything not even 0

1st Mar 2022, 6:18 AM

NonStop CODING

what is the different between Null & Empty?! | Sololearn: Learn to code for FREE! (2)

+ 1

Please tag relevant languages only, the method you mentioned (string.IsNullOrEmpty) is C# specific. In other languages it may not be available, or may require some extra steps to confirm the object (being null or empty).https://code.sololearn.com/W3uiji9X28C1/?ref=app

1st Mar 2022, 6:15 AM

Ipang

what is the different between Null & Empty?! | Sololearn: Learn to code for FREE! (2024)
Top Articles
Latest Posts
Article information

Author: Arielle Torp

Last Updated:

Views: 6109

Rating: 4 / 5 (61 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Arielle Torp

Birthday: 1997-09-20

Address: 87313 Erdman Vista, North Dustinborough, WA 37563

Phone: +97216742823598

Job: Central Technology Officer

Hobby: Taekwondo, Macrame, Foreign language learning, Kite flying, Cooking, Skiing, Computer programming

Introduction: My name is Arielle Torp, I am a comfortable, kind, zealous, lovely, jolly, colorful, adventurous person who loves writing and wants to share my knowledge and understanding with you.