I tried some parsing, using hardcoded value or variable, but result is
the same. Even declaring variable as constant does not help
Actually, if you check DateTime Struct you would seen Hour property within it which should look like as following:

Therefore, when you would pass or evaluate any time comparison you ought to extract the hour from given format for your scenario which is HH:mm:ss. Once you would extract the hour now you could execute your comparison using switch statement.
Let's check in action what you are trying to achieve.
TimeOnly testTimeOnly = TimeOnly.ParseExact("00:00:00", "HH:mm:ss", CultureInfo.InvariantCulture);
TimeOnly testMorning = TimeOnly.ParseExact("06:00:00", "HH:mm:ss", CultureInfo.InvariantCulture);
var checkNight = testTimeOnly.Hour;
var checkMorning = testMorning.Hour;
switch (checkNight)
{
case int time when (time >= 6 && time <= 12):
Console.WriteLine($"Hello , good morning");
break;
case int time when (time >= 12 && time <= 17):
Console.WriteLine($"Hello , good afternoon");
break;
case int time when (time >= 0):
Console.WriteLine($"Hello ,{testTimeOnly} Its night right now");
break;
default:
Console.WriteLine($"Unknown part of the day!");
break;
}
Note: As you can see I am extracting hour from testTimeOnly which will return 0 means over 23.
Output:

Daynamic Comparison:
However, if you would like to extract and compare dynamic time reagrdless of time zone the elegant way would be as following:
DateTime dateTime = DateTime.Now;
DateTime utcTime = dateTime.ToUniversalTime();
TimeZoneInfo cstZone = TimeZoneInfo.FindSystemTimeZoneById("China Standard Time");
DateTime yourLocalTime = TimeZoneInfo.ConvertTimeFromUtc(utcTime, cstZone);
var hour = yourLocalTime.Hour;
switch (hour)
{
case int time when (time >= 0 && time <= 5):
Console.WriteLine($"Hello ,Its mid night now");
break;
case int time when (time >= 6 && time <= 12):
Console.WriteLine($"Hello , Its morning now");
break;
case int time when (time >= 12 && time <= 17):
Console.WriteLine($"Hello , Its after noon");
break;
case int time when (time >= 17 && time <= 19):
Console.WriteLine($"Hello , Its evening");
break;
case int time when (time >= 19 && time <= 23):
Console.WriteLine($"Hello , Its Night");
break;
default:
Console.WriteLine($"Hello and welcome!");
break;
}
In addition to this, you can get your required time zone here.
Note: If you would like to know more details on time conversion you could check our official document here