The pilot reported that when he selected the landing gear up after takeoff, it remained down and the three green lights remained illuminated. After checking the circuit breakers, several more attempts were made to retract the landing gear without success. During the subsequent landing, the landing gear collapsed and the aircraft settled onto its underside. The only fault revealed during examination of the landing gear system was varying resistance in the right landing gear safety switch (the squat switch). This intermittent fault could have prevented the landing gear from retracting. The pilot reported that he conducted a smooth landing because of the nature of the problem. Despite that, it could have been sufficient to free the switch and allow the retraction cycle to begin as the oleos were compressed but before the safety switch was made. However, this could only have happened if the langing gear selector was in the up position.