Click here to Skip to main content
15,899,679 members
Home / Discussions / C#
   

C#

 
GeneralRe: Socket closing without FIN from peer Pin
MidwestLimey18-Mar-16 14:17
professionalMidwestLimey18-Mar-16 14:17 
QuestionHow can i create a dialog box window in asp.net C# (web) which contains many field? Pin
Hameed Khan17-Mar-16 5:35
Hameed Khan17-Mar-16 5:35 
AnswerRe: How can i create a dialog box window in asp.net C# (web) which contains many field? Pin
OriginalGriff17-Mar-16 6:28
mveOriginalGriff17-Mar-16 6:28 
SuggestionRe: How can i create a dialog box window in asp.net C# (web) which contains many field? Pin
Richard Deeming17-Mar-16 6:58
mveRichard Deeming17-Mar-16 6:58 
GeneralRe: How can i create a dialog box window in asp.net C# (web) which contains many field? Pin
OriginalGriff17-Mar-16 7:10
mveOriginalGriff17-Mar-16 7:10 
QuestionRe: How can i create a dialog box window in asp.net C# (web) which contains many field? Pin
ZurdoDev17-Mar-16 10:15
professionalZurdoDev17-Mar-16 10:15 
AnswerRe: How can i create a dialog box window in asp.net C# (web) which contains many field? Pin
F-ES Sitecore18-Mar-16 0:37
professionalF-ES Sitecore18-Mar-16 0:37 
QuestionTime Elapse Pin
Aelmfr16-Mar-16 13:57
Aelmfr16-Mar-16 13:57 
AnswerRe: Time Elapse Pin
Garth J Lancaster16-Mar-16 14:30
professionalGarth J Lancaster16-Mar-16 14:30 
GeneralRe: Time Elapse Pin
Aelmfr16-Mar-16 14:46
Aelmfr16-Mar-16 14:46 
AnswerRe: Time Elapse Pin
Patrice T16-Mar-16 14:37
mvePatrice T16-Mar-16 14:37 
GeneralRe: Time Elapse Pin
Aelmfr16-Mar-16 14:53
Aelmfr16-Mar-16 14:53 
GeneralRe: Time Elapse Pin
Patrice T16-Mar-16 15:08
mvePatrice T16-Mar-16 15:08 
GeneralRe: Time Elapse Pin
Aelmfr16-Mar-16 15:44
Aelmfr16-Mar-16 15:44 
GeneralRe: Time Elapse Pin
Patrice T16-Mar-16 15:58
mvePatrice T16-Mar-16 15:58 
GeneralRe: Time Elapse Pin
Garth J Lancaster16-Mar-16 16:06
professionalGarth J Lancaster16-Mar-16 16:06 
GeneralRe: Time Elapse Pin
Patrice T16-Mar-16 16:11
mvePatrice T16-Mar-16 16:11 
JokeRe: Time Elapse Pin
Richard Deeming17-Mar-16 2:00
mveRichard Deeming17-Mar-16 2:00 
PraiseRe: Time Elapse Pin
Patrice T17-Mar-16 4:32
mvePatrice T17-Mar-16 4:32 
AnswerRe: Time Elapse Pin
V.16-Mar-16 22:15
professionalV.16-Mar-16 22:15 
QuestionConverting Array To Dictionary Pin
MadDashCoder16-Mar-16 11:16
MadDashCoder16-Mar-16 11:16 
I am trying to convert an array to a dictionary but my code is throwing a null exception. Below is my code
C#
    static void Main(string[] args)
    {
        Product p1 = new Product();
        p1.ProductSkew = 99;
        p1.ProductName = "Accord";
        p1.Color = "Black";
        p1.Price = 35000;

        Product p2 = new Product();
        p2.ProductSkew = 46;
        p2.ProductName = "Corvette";
        p2.Color = "Black";
        p2.Price = 65000;

        Product p3 = new Product();
        p3.ProductSkew = 35;
        p3.ProductName = "Altima";
        p3.Color = "Black";
        p3.Price = 32000;

        Product[] products = new Product[3];

        products[0] = p1;
        products[1] = p2;
        products[2] = p3;

        Dictionary<int, Product> productlist = products.ToDictionary(p => p.ProductSkew, p => p);

        foreach (KeyValuePair<int, Product> item in productlist)
        {
            Product product = new Product();
            product = item.Value;

            Console.WriteLine(
            "\nSkew: {0} \n" + "Name: {1} \n" +  "Color: {2} \n" +  "Price: {3} \n",
            product.ProductSkew, product.ProductName, product.Color, product.Price );
        }
        Console.ReadLine();
    }
}

public class Product
{
    public int ProductSkew { get; set; }
    public string ProductName { get; set; }
    public string Color { get; set; }
    public double Price { get; set; }

    public void AddProduct()
    {
        Console.WriteLine("Enter Product Skew.");
        this.ProductSkew = Convert.ToInt32(Console.ReadLine());

        Console.WriteLine("Enter Product Name.");
        this.ProductName = Console.ReadLine();

        Console.WriteLine("Enter Product Color.");
        this.Color = Console.ReadLine();

        Console.WriteLine("Enter Product Price.");
        this.Price = Convert.ToDouble(Console.ReadLine());
    }
}


The syntax seems correct but when I step through the code inside of ToDictionay(), p.ProduckSkew is empty and I don't know why. Any help is greatly appreciated, thanks.
AnswerRe: Converting Array To Dictionary Pin
John Torjo16-Mar-16 11:22
professionalJohn Torjo16-Mar-16 11:22 
GeneralRe: Converting Array To Dictionary Pin
MadDashCoder16-Mar-16 11:32
MadDashCoder16-Mar-16 11:32 
AnswerRe: Converting Array To Dictionary Pin
Matt T Heffron16-Mar-16 11:47
professionalMatt T Heffron16-Mar-16 11:47 
AnswerRe: Converting Array To Dictionary Pin
Mathi Mani16-Mar-16 11:47
Mathi Mani16-Mar-16 11:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.