Click here to Skip to main content
15,885,651 members
Home / Discussions / C#
   

C#

 
QuestionConsole Check Pin
Bassam Abdul-Baki9-Apr-13 5:53
professionalBassam Abdul-Baki9-Apr-13 5:53 
AnswerRe: Console Check Pin
Pete O'Hanlon9-Apr-13 6:14
mvePete O'Hanlon9-Apr-13 6:14 
GeneralRe: Console Check Pin
Bassam Abdul-Baki9-Apr-13 6:39
professionalBassam Abdul-Baki9-Apr-13 6:39 
AnswerRe: Console Check Pin
MicroVirus10-Apr-13 0:33
MicroVirus10-Apr-13 0:33 
GeneralRe: Console Check Pin
Bassam Abdul-Baki10-Apr-13 1:04
professionalBassam Abdul-Baki10-Apr-13 1:04 
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 
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
this is the THIRD one
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; }       
    }
}


SQL
Q3) Let us take a view of this part of the coding:-

 public void AddDocument(T doc) // //************************3
"T  doc" may create a reference variable to an object called doc
but instead of passing a reference variable we are passing an object in the method call as:-

 dm.AddDocument(new Document("Title A", "Sample A"));//************************4
etc ....
case1)  Why this anomaly?
Case2)   Can we intuitively know from a coding where it is a reference variable that is to be passed as a paremeter and where an object is to be passed as a parameter?

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 
AnswerRe: Constrained object in C# Pin
Pete O'Hanlon8-Apr-13 22:51
mvePete 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 

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.