.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Abstract class properties work when not implemented?

Posted By:      Posted Date: August 28, 2010    Points: 0   Category :.NET Framework
Hi, I was just looking at a code example and was confused by the behavior of classes implementing an abstract class. So the project has an abstract class named GeneralItem with some abstract properties. Another class named NspItem inherits GeneralItem. NspItem does not implement any of the abstract properties from GeneralItem yet I can write code that successfully sets those properties. How is that working? Is the compiler automatically creating them for me? Example: public abstract class GeneralItem { public string Description { get; set; } } public class NspItem : GeneralItem { public NspItem() { } } static class Program { [STAThread] static void Main() { NspItem item = new NspItem(); item.Description = "Some String"; Console.WriteLine(item.Description); } } //Output would be: Some String

View Complete Post

More Related Resource Links

abstract away the source of the connection string using a class with a static property.

ASP.NET provides a configuration system we can use to keep our applications flexible at runtime. In this article we will examine some tips and best practices for using the configuration system for the best results.

The element of a web.config file is a place to store connection strings, server names, file paths, and other miscellaneous settings needed by an application to perform work. The items inside appSettings are items that need to be configurable depending upon the environment, for instance, any database connection strings will change as you move your application from a testing and staging server into production.

Let's abstract away the source of the connection string using a class with a static property.

Singleton Pattern and Abstract Class


I know what Singleton Pattern means and Abstract class means.

What I wanted to know was how would this apply to real world.

Could anyone give me any good example or simple explanation.

Say I have a simple website, why would I use any of the above if any.

Why would it simplify my architechture.

Thanks in advace. 

All data in class properties disappear across WCF service

Hi, I have a class that i share betwee silverlight client and wcf service. I populate properties of the class with real data from the client, to be used in the server. I use debugger to step through the code when the call gets to the server, all the data ara gone and are replaced with null. All DateTime value change to 1/1/1001. But if pass primitive types such as int, string, no problem. This is happening only on one machine, but not on ther machine. Can someone tell me what is going on here? Thanks in advance

Some Useful Properties of Binding Class

When binding the UI control with the data source the Binding class has some useful properties.In this post we will look at them and use them in sample application. The properties which we are going to discuss in this post are the FallbackValue ,TargetNullValue, and StringFormat. Image 1 shows the output of the example code.

when abstract class and when interface

hi...need a practical scenario where interface can be used and where abstract class and also the need for constructors and destructors practically?? theoritically i know the differences ..but during coming to the implementation how to decide??...like why do u declare a class as abstract... thanks in advance 

WPF designer: How to specify/show sub-properties (ExpandableObjectConverter does not work)?


Hi All,

I'm instantiating some class using Window.Resources tag:


 <b1:CaMyClass x:Key="myClass1" InitialDirectory="c:\">



The problem is that CaMyClass also has nested object property so I can specify them in code-behind like this:

myClass1.Styles.StyleA = ...;

myClass1.Styles.StyleB = ...;

WPF designer: How to specify/show sub-properties (ExpandableObjectConverter does not work)?


Hi All,

I'm instantiating some class using Window.Resources tag:


 <b1:CaMyClass x:Key="myClass1" InitialDirectory="c:\">



The problem is that CaMyClass also has nested object property so I can specify them in code-behind like this:

myClass1.Styles.StyleA = ...;

myClass1.Styles.StyleB = ...;

Assign values to base class properties


In my controller have a FormViewModel which inherits from a domain class declared in dbml.  In the constructor of the FormViewModel I want to do a shorthand assignment to the inherited class properties with the passed in object (ie thisPerson) without iterating through each property of the inherited class and assigning its value with corresponding property in the passing in object. Should I use super, base, this, or something else?

public MyFormViewModel: Person
  public SelectList Cities {get; private set;}
  public SelectList State {get; private set;}

  public MyFormViewModel(){}

  public MyFormViewModel(Person thisPerson) 

        this = thisPerson; 
     //or super = thisPerson;
     //base = thisPerson;


Use UserControl, where the base class is an abstract one.




When I inherits my usercontrol from an abstract class, I got the warning message on design time.

How can I overcome this warning message?

The designer must create an instance of type but it cannot because the type XYZ is declared as abstract.


Thanks :)

Serialize a Class's properties as XML Attributes instead if Elements


Say you have a 3rd party provided assembly with a class like so:

User user = new User();

user.UserId = 1;
user.UserName = "johndoe";
user.Password = "password";


When serialized with the XmlSerializer it comes out something like this:


How to get validation to work for buddy class in 2 screens


I have set up my buddy class with validators. However I only want the validators to fire of the associated fields are used in that particular screen. When I split them across 2 screens I find my validation doesn't work. How do I fix this? I have had to remove the validation from some properties in order to get it to work on one screen;

See the class here;

        #region "Buddy class" for validation
        /// <summary>
        /// This "buddy class" provides validation for a class generated from EF
        /// </summary>
        private sealed class Metadata

How to create a Class with List<> as properties



I need some help for the above.


I need to read filenames into a List  inside a class.


Example :

1) How to read or get the value into the PhotoNameCollection Class in foreach statement below?


2) How to create a class with List<> as properties and How to do the get and set statement ? Is the below class okk?


 foreach (var pic in PicNames)

     //-- get the filename and add it into the class with List<>


  public class PhotoNameCollection  //<--- Can be Static Class
        private List<string> g_Photoname

        public List<string> PhotoName



Trouble showing class properties


I'm sorry in advance if my explanation isn't very clear. It's a bit hard to put to words what I'm trying to accomplish. That said here we go...

Does anybody know how to show class properties after instantiating the class in code? I have a class Employee and when I type a '.' after the employee object I see a list of properties and functions. The problem comes when I select a property that itself has additional properties.

Employee x = new Employee();

//when i type the '.' after the object "x" I see a list that has "ID," "Department," and "ListOfItems."

x.ID = 10;
x.Department = "Sales"

//I should see a list of properties when i type '.' after the property "ListOfItems" and I do not.

If I enter a valid property of the "ListOfItems" collection class it will let me view the value, but I'd like to see the list none the less.

Any help would be greatly appreciated. Thanks in advance!

Abstract Class


what is the function of abstract class, why design pattern need to build BLL and DAL

anyone give an example for my reference as I am getting strat to build my web-based  project 

Manage user Properties - Changed property "work phone" Property mapping for Synchronization but user


Hi, I've changed the a user profile settings in CA (see below) so it is no longer mapped to AD, but when I edit the user profile in SharePoint MySite I have a yellow triangle with an exclaimation mark that states "indicated a filed that is updated automatically from the corporate directory. Changes to these properties may be lost. But I have removed the mapping as above. Am I missing some thing or is there a job that I need to run to carry the update through.   

I made the change in  - "user profile service application - manage user properties - Work phone" I have removed the "property mapping for Synchronization" so it now displays "There are no items to show in this view" - Do I need to make further changes to carry this through? 

Failed to read Mysite(hosted on port: 80) profile properties using Work flow



I developed a sequential work flow to read My site profile properties. Which is working fine in development and test servers but not in production server.

My development and test server have my sites hosted on port number other than port 80. I am having no issues here working my code. I just pass my site URL to SPSite object...

SPSite site = new SPSite("http://developmentserver:5252/");

SPSite site = new SPSite("http://testserver:2383/");

Coming to the production server, I have my sites hosted on port 80. I change my sites URL to

SPSite site = new SPSite("http://mysites");

My work flow runs with out any error but it is not doing as it suppose to do. Think, it is not reading any profile properties. I am unable to debug the code as production server is 64 bit computer. I even changed my sites URL with complete domain name qualifying.

PSite site = new SPSite("http://mysites.domain.com");

Please help me to resolve this. I really appreciate your help!






C# auto-implemented properties: please explain


 Hi all...I'm learning ASP.NET, and I have Java experience, but am obviously having to switch to C# to use ASP.NET...I am working through the MVCMusicStore tutorial, and I just need a bit of a clarification on this comment the tutorial makes. They say to declare the following class:

public class StoreIndexViewModel
public int NumberOfGenres { get; set; }
public List<string> Genres { get; set; }

Then they say: "Note: In case you're wondering, the { get; set; } notation is making use of C#'s auto-implemented properties feature. This gives us the benefits of a property without requiring us to declare a backing field." What are they taking about exactly? Like in Java I would create get_Genres, set_Genres, get_NumberOfGenres, and set_NumberOfGenres methods and declare these variables as private not public, to protect my data. But in C#, is this same basic thing? Is the data still being protected? I would appreciate any input. Thanks

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend