Some kinds of N-containing heterocyclic compounds were prepared and their $pK_a$ values were determined as part of their structures and reaction studies. By the values determined in this work, the basicities of exocyclic N-containing thiazoles were much higher than those generally expected. 3-Substituted-5,6-dihydroimidazo[2,1-b]thiazoles 25 and 26 reacted readily with $\alpha$-haloketones or $\alpha$-haloester such as 2-bromoacetohpenones or ethyl bromoacetate in acetone at room temperature, providing the corresponding 3,7-disubstituted-5,6-dihydroimidazo[2,1-b]thiazolium bromides 31. In addition, 3-phenyl-6,7-dihydro-5H-thiazolo[3,2-a]pyrimidinium bromides 32 were synthesized by N-alkylation of 3-phenyl-6,7-dihydro-5H-thiazolo[3,2-a]pyrimidine (30) and 2-bromoacetophenones or ethyl bromoacetate in more mild condition, in benzene at 10$^\circ$C. 3-Methyl-2-methylimino-4-phenyl-$\triangle^4$-thiazoline (28) reacted with ethyl bromoacetate in refluxing benzene, giving the corresponding N-alkylated salt 33, while the products obtained in reaction with $\alpha$-bromoacetophenone were not the simple N-alkylated compound but the mixture of 3-methyl-2-methylimino-4-phenyl-$\triangle^4$-thiazolium bromide (34) and pyrrolothiazine 35. We have proposed the mechanism of this reaction that iminothiazoline 28 acts not only as a nucleophile but also as a base. The imidazothiazolium betaines 42 were generated in situ from the imidazothiazolium bromides 31 and triethylamine. The reaction of these imidazothiazolium betaines with ethyl propiolate provided geometric cis, trans ismers 43 and 44 containing 2,3-dinydro-1H-pyrrolo[1,2-a]imidazole. We have proposed the mechanism of this reaction that involves 1,3-dipolar cycloaddition, isomeric rearrangement, and then nucleophilic addition successively. The ratio of trans and cis, isomers was depended on the temperature and solvents. The stereoselectivity of trans isomers iscreased with increasing temperature and decreasing polarity ...