c# best way to declare a class-level value in base class and set it at derived classes I have a root class and I'd like to add an indicator to it (property, static field, readonly field, virtual method or something like that), that should give me the same string value for every instance of that class, I would rather prefer to get that value without instantiating that class. GetObjType() virtual method is my current implementation of it but I am thinking there may a better way of doing this. Can you think of a better way of doing this, like class level singleton fields or something like that.

public abstract class CoreEntity
{
    public int Id { get; set; }
    public abstract string GetObjType();
}
public class DepartmanBase : CoreEntity
{
    public override string GetObjType() 
    {return "DEPARTMAN";}
    public string DepartmanName { get; set; }
    public int ManagerId { get; set; }
    //Obj Type should be set as "DEPARTMAN" here and should be same in both derived classes
}
public class Departman : DepartmanBase
{
}
public class DepartmanView : DepartmanBase
{
    public string ManagerName { get; set; }
}

public class Personnel : CoreEntity
{
    public override string GetObjType() {return "PERSONEL";}
    public string PersonnelName { get; set; }
}

public class Repository&lt;T&gt;
    where T : CoreEntity , new()
{
    public void DoSomething()
    {
        string objType = new T().GetObjType();
        Console.WriteLine("Object Type for: " + typeof(T).Name  + " is " + objType);
    }
}

void Main()
{
    var d = new Repository&lt;Departman&gt;();
    var dv = new Repository&lt;DepartmanView&gt;();
    var p = new Repository&lt;Personnel&gt;();

    d.DoSomething();
    dv.DoSomething();
    p.DoSomething();
}
What I've guessed from your code (and I might be wrong) is that you need to get some string from a type used in a persistence layer. The string might be a table name, or a value for a certain column. I've decided to call this a discriminator. Multiple types can have the same discriminator but each type can only have one.

I think it makes sense to introduce an inheritable attribute here, let's do that:

[AttributeUsage(AttributeTargets.Class, Inherited = true, AllowMultiple = false)]
sealed class DiscriminatorAttribute : Attribute
{
    readonly string discriminator;

    public DiscriminatorAttribute(string discriminator) 
   { 
        this.discriminator = discriminator;
   }

    public string Discriminator
    {
        get { return discriminator; }
    }
}


We'll also add a class which takes a type and gets us our string (if we have one).

public static class DiscriminatorService
{
    public static string LookupDiscriminatorForType(Type t)
    {
        var result = (from a in t.GetCustomAttributes(true)
                 where a is DiscriminatorAttribute
                 select a).SingleOrDefault() as DiscriminatorAttribute;
        return result != null ? result.Discriminator : null;
    }
}


This will allow you to change your repository to the following:

public class Repository&lt;T&gt; where T : CoreEntity
{
    public void DoSomething()
    {
        var objType = DiscriminatorService.LookupDiscriminatorForType(typeof(T));
        Console.WriteLine("Object Type for: " + typeof(T).Name  + " is " + objType);
    }
}


Some important things to note:


You no longer need to create an instance to get the string
you can remove the new() generic constraint


Obviously you need to decorate your classes with the new attribute:

[Discriminator("DEPARTMAN")]
public class DepartmanBase : CoreEntity
{
    public string DepartmanName { get; set; }
    public int ManagerId { get; set; }
}
public class Departman : DepartmanBase
{
    // Inherits discriminator from DepartmanBase
}

public class DepartmanView : DepartmanBase
{
    // Inherits discriminator from DepartmanBase
    public string ManagerName { get; set; }
}

[Discriminator("PERSONEL")]
public class Personnel : CoreEntity
{
    public string PersonnelName { get; set; }
}


Here's the full code in .Net Fiddle