Friday, May 27, 2016

FormatException was unhandled , Input string was not in a correct format

This sample shows a Person class that has two properties: Name (string) and Age (int). Both properties are read/write.

Without Errors Code Msdn Properties Tutorial


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Person
    {
        private string myName;
        private int myAge;
        //Declare Name Property of a String
        public String Name
        {
            get
            {
                return myName;
            }
            set
            {
                myName = value;
            }

        }
        //Declare Age Property of a integer
        public int Age
        {
            get
            {
                return myAge;
            }
            set
            {
                myAge = value;

            }
        }
        public override string ToString()
        {
            return "Name = " + Name + ", Age = " + Age; ;
            }


        static void Main(string[] args)
        {
            Person person = new Person();

            Console.WriteLine("Person details -{0}", person);

            //Set some values on person objects
            person.Age = 25;
            person.Name = "Awareness";
            Console.WriteLine("Person details -{0)", person);

            person.Age += 20;
            Console.WriteLine("Person Details -{0}", person);
              Console.ReadKey();
        }
    }

}

Note : Red Color Mark Indicates Cause Of Error

Conclusion: Change the bracket to Flower Bracket in this Program.

output:
Person details -Name = , Age = 0
Person details -Name = Awareness, Age = 25
Person Details -Name = Awareness, Age = 45

After Execution Program:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Person
    {
        private string myName;
        private int myAge;
        //Declare Name Property of a String
        public String Name
        {
            get
            {
                return myName;
            }
            set
            {
                myName = value;
            }

        }
        //Declare Age Property of a integer
        public int Age
        {
            get
            {
                return myAge;
            }
            set
            {
                myAge = value;

            }
        }
        public override string ToString()
        {
            return "Name = " + Name + ", Age = " + Age; ;
            }


        static void Main(string[] args)
        {
            Person person = new Person();

            Console.WriteLine("Person details -{0}", person);

            //Set some values on person objects
            person.Age = 25;
            person.Name = "Awareness";
            Console.WriteLine("Person details -{0}", person);

            person.Age += 20;
            Console.WriteLine("Person Details -{0}", person);
            Console.ReadKey();
        }
    }
}

Thursday, May 26, 2016

System.Array' does not contain a definition for 'length' and no extension method 'length' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Learn
{
class Arrays
{
static void Main(String[] args)
{
//Single Dimenstional Array
int[] numbers=new int[4];

//Two Dimenstional Array
string[,] twoNum=new string[4,5];

//Arrays of Arrays (Jagged)

byte[][] score = new byte[5][];

for(int i=0;i<score.length;i++)
{
score[i]=new byte[i+3];
}

for(int i=0;i<score.length;i++)
{
Console.WriteLine("Row Number{0} and its value is{1}",i,score[i].length);
}
Console.ReadLine();

}
}
}
Note: Red Color Indicates Cause Of Error.

After Completing Errors are :



cs(22,24): error CS1061: 'System.Array' does not contain a definition for 'length' and no extension method 'length' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?)


 cs(27,24): error CS1061: 'System.Array' does not contain a definition for 'length' and no extension method 'length' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?)

 cs(29,71):error CS1061: 'System.Array' does not contain a definition for 'length' and no extension method 'length' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?)

Conclusion is : Change length to Length.

Output of Programming is :

C:\Users\Vijay\Documents\Visual Studio 2012\Projects\Learn>Arrays
Row Number 0 and its value is 3
Row Number 1 and its value is 4
Row Number 2 and its value is 5
Row Number 3 and its value is 6
Row Number 4 and its value is 7

After Execution Programming is

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Learn
{
class Arrays
{
static void Main(String[] args)
{
//Single Dimenstional Array
int[] numbers=new int[4];

//Two Dimenstional Array
string[,] twoNum=new string[4,5];

//Arrays of Arrays (Jagged)

byte[][] score = new byte[5][];

for(int i=0;i<score.Length;i++)
{
score[i]=new byte[i+3];
}

for(int i=0;i<score.Length;i++)
{
Console.WriteLine("Row Number {0} and its value is {1}", i , score[i].Length );
}
Console.ReadLine();

}
}
}