Sponsored Ad

Friday, February 25, 2011

Property or Indexer my_class Cannot be Assigned to -- it is read only : C# Error

This is common C# error. Read Only Error occur when you try to assign values to a property or indexer, which is readonly. In other words the property do not have set accessors define. uncomment the below code and it will work.

using System;

namespace MyApp
{
    class my_class
    { 
        //int my_value;
        int I
        {
            get
            {
                return 1;
            }

            //set
            //{
            //    my_value = value;
            //}
        }

        static void Main(string[] args)
        {
            my_class obj = new my_class();
            obj.I = 20;  
            Console.ReadLine();
        }
    }
}

Sunday, February 20, 2011

How to Load XML and Print on Console using C#

This simple C# example will help you to load the XML doc and Print on the console using Console.WriteLine. LoadXml is used to load the XML from a string into XML Document.

How to Load XML and Print on Console using C#

How to LoadXML and Print:

using System;
using System.IO;
using System.Xml;
namespace MyApp
{
    class my_XML
    {
        static void Main(string[] args)
        {
            XmlDocument objDoc = new XmlDocument();
            String strContent = "<Tutorial Type='CSharp_XML'><title>This is CSharp XML Example</title>" +
             "</Tutorial>";
            objDoc.LoadXml(strContent);

            StringWriter objWriter = new StringWriter();
            objDoc.Save(objWriter);
            String strXML = objWriter.ToString();
            Console.WriteLine(strXML);

            Console.ReadLine();
        }
    }
}

Sponsored Ad

Development Updates