Click here to Skip to main content
15,867,704 members
Home / Discussions / C#
   

C#

 
QuestionEntering values to an int List Pin
aaa@gmail.com9-Apr-13 5:35
aaa@gmail.com9-Apr-13 5:35 
AnswerRe: Entering values to an int List Pin
OriginalGriff9-Apr-13 5:54
mveOriginalGriff9-Apr-13 5:54 
Questionref var of object inside a method Pin
Member 99394238-Apr-13 20:58
Member 99394238-Apr-13 20:58 
GeneralRe: ref var of object inside a method Pin
harold aptroot9-Apr-13 2:55
harold aptroot9-Apr-13 2:55 
GeneralRe: ref var of object inside a method Pin
Member 99394239-Apr-13 3:34
Member 99394239-Apr-13 3:34 
GeneralRe: ref var of object inside a method Pin
harold aptroot9-Apr-13 4:00
harold aptroot9-Apr-13 4:00 
QuestionConstrained generic class concepts Pin
Member 99394238-Apr-13 20:55
Member 99394238-Apr-13 20:55 
QuestionConstrained object in C# Pin
Member 99394238-Apr-13 20:52
Member 99394238-Apr-13 20:52 
CSS
there is a program of a document manager that pushes the document to a Queue
There are 3 questions on 3 different threads, base on the same program
the program is :-

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

namespace scratchpad3
{
    class Program
    {
        public static void Main()
        {
            var dm = new DocumentManager<Document>(); //************************2
            dm.AddDocument(new Document("Title A", "Sample A"));//**************4
            dm.AddDocument(new Document("Title B", "Sample B"));
            dm.DisplayAllDocuments();
            if (dm.IsDocumentAvailable)
            {
                Document d = dm.GetDocument();
                Console.WriteLine(d.Content);
                Console.Read();
            }

        }
    }

//    >>>>>>>>>>>>>>>>>>>>>>>>> decl of a class
    public class DocumentManager<T>
where T : IDocument			//************************1
    {
        private readonly Queue<T> documentQueue = new Queue<T>();
        public void AddDocument(T doc) //************************3
        {
            lock (this)
            {
                documentQueue.Enqueue(doc);
            }
        }
        public bool IsDocumentAvailable
        {
            get { return documentQueue.Count > 0; }
        }

        public T GetDocument()
        {
            T doc = default(T);
            lock (this)
            {
                doc = documentQueue.Dequeue();
            }
            return doc;
        }
         public void DisplayAllDocuments()
        {
            foreach (T doc in documentQueue)
            {
                Console.WriteLine(doc.Title);
            }
        }



    }

//>>>>>>>>>>>>>>>>>>>>>>>>>>>>> decl of a class
    public interface IDocument
    {
        string Title { get; set; }
        string Content { get; set; }
    }
    public class Document : IDocument
    {
        public Document()
        {
        }
        public Document(string title, string content)
        {
            this.Title = title;
            this.Content = content;
        }
        public string Title { get; set; }
        public string Content { get; set; }       
    }
}


XML
Please refer to line indicated as "//************************1"
Q1)  How would these 2 declarations and its corrosponding objects differ :
i )
IDocument  ido = new IDocument();
and
ii)
 public class DocumentManager<T> where T : IDocument {// code}
 var dm = new DocumentManager<IDocument>(); // pls note this IS A DEVIATION form // the code

AnswerRe: Constrained object in C# Pin
Pete O'Hanlon8-Apr-13 22:51
subeditorPete O'Hanlon8-Apr-13 22:51 
QuestionCan I display links in a ListView's detail mode? Pin
NarVish8-Apr-13 20:33
NarVish8-Apr-13 20:33 
Questionc# application don't work on xp Pin
Member 99694278-Apr-13 10:39
Member 99694278-Apr-13 10:39 
AnswerRe: c# application don't work on xp Pin
fjdiewornncalwe8-Apr-13 10:54
professionalfjdiewornncalwe8-Apr-13 10:54 
AnswerRe: c# application don't work on xp Pin
Manfred Rudolf Bihy8-Apr-13 20:02
professionalManfred Rudolf Bihy8-Apr-13 20:02 
Questionadvanced settings Pin
bfis1081378-Apr-13 10:13
bfis1081378-Apr-13 10:13 
AnswerRe: advanced settings Pin
SledgeHammer018-Apr-13 10:15
SledgeHammer018-Apr-13 10:15 
GeneralRe: advanced settings Pin
bfis1081378-Apr-13 10:18
bfis1081378-Apr-13 10:18 
GeneralRe: advanced settings Pin
SledgeHammer018-Apr-13 11:16
SledgeHammer018-Apr-13 11:16 
GeneralRe: advanced settings Pin
bfis1081378-Apr-13 18:22
bfis1081378-Apr-13 18:22 
GeneralRe: advanced settings Pin
SledgeHammer018-Apr-13 18:33
SledgeHammer018-Apr-13 18:33 
GeneralRe: advanced settings Pin
bfis1081378-Apr-13 18:45
bfis1081378-Apr-13 18:45 
GeneralRe: advanced settings Pin
SledgeHammer018-Apr-13 18:48
SledgeHammer018-Apr-13 18:48 
GeneralRe: advanced settings Pin
bfis1081378-Apr-13 18:51
bfis1081378-Apr-13 18:51 
GeneralRe: advanced settings Pin
SledgeHammer018-Apr-13 19:08
SledgeHammer018-Apr-13 19:08 
GeneralRe: advanced settings Pin
bfis1081378-Apr-13 21:16
bfis1081378-Apr-13 21:16 
AnswerRe: advanced settings Pin
Alan N9-Apr-13 1:54
Alan N9-Apr-13 1:54 

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.