how can i compare between two objects using getType method
i want to know if two objects are from the same class or from the same base class

To get object type

Program p = new Program();
Console.WriteLine(p.GetType().Name);//prints Program

To get object base type

Program p = new Program();
Console.WriteLine(p.GetType().BaseType.Name);//prints Object (the base class of Program class)

To compare between two objects you just need to use string.Compare....

Don't use old threads :p

List< String >  names = new List< String >();
names.Add("Serkan");
if(names.GetType().IsGenericType)
Console.WriteLine(names[0].GetType().Name);

what you show works when there is an item in that list, what if the list is empty?

here i tested your code with example and it works, i attach the working example too, but tell me if you didnt add an item to that list, how would you understand the type?

Form1.cs :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication13
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
		}

		private class someClass
		{
		}
		private void button1_Click(object sender, EventArgs e)
		{

			someClass sc1 = new someClass();
			List<someClass> g = new List<someClass>();
			g.Add(sc1);
			if (g.GetType().IsGenericType)
				MessageBox.Show(g[0].GetType().Name);
		}
	}
}

but i have a special case where i dont have an item in that list. that is why i asked. the item is added at run time, so at compile time you dont know the item. But anyway i am tired, i cant think of another solution either.

This question has already been answered. Start a new discussion instead.