Click here to Skip to main content
15,891,607 members
Home / Discussions / C#
   

C#

 
GeneralRe: HOW CAN I MAKE PARAMETER THAT TAKE A PERIOD OF MONTHS AS A PARAMETER IN C# Pin
User349010-Apr-13 4:11
User349010-Apr-13 4:11 
GeneralRe: HOW CAN I MAKE PARAMETER THAT TAKE A PERIOD OF MONTHS AS A PARAMETER IN C# Pin
OriginalGriff10-Apr-13 4:29
mveOriginalGriff10-Apr-13 4:29 
GeneralRe: HOW CAN I MAKE PARAMETER THAT TAKE A PERIOD OF MONTHS AS A PARAMETER IN C# Pin
User349010-Apr-13 4:56
User349010-Apr-13 4:56 
GeneralRe: HOW CAN I MAKE PARAMETER THAT TAKE A PERIOD OF MONTHS AS A PARAMETER IN C# Pin
JesperMadsen12310-Apr-13 6:14
JesperMadsen12310-Apr-13 6:14 
Questionclass question Pin
Member 99710549-Apr-13 12:33
Member 99710549-Apr-13 12:33 
AnswerRe: class question Pin
Pete O'Hanlon9-Apr-13 12:36
mvePete O'Hanlon9-Apr-13 12:36 
AnswerRe: class question Pin
Abhinav S9-Apr-13 16:14
Abhinav S9-Apr-13 16:14 
AnswerRe: class question Pin
Bernhard Hiller9-Apr-13 23:46
Bernhard Hiller9-Apr-13 23:46 
QuestionProblems with SharpGL Control Pin
Aarón C de C9-Apr-13 11:05
Aarón C de C9-Apr-13 11:05 
Questionintegrating clips with c# Pin
Farhaneh9-Apr-13 5:58
Farhaneh9-Apr-13 5:58 
AnswerRe: integrating clips with c# Pin
Pete O'Hanlon9-Apr-13 6:11
mvePete O'Hanlon9-Apr-13 6:11 
GeneralRe: integrating clips with c# Pin
Farhaneh9-Apr-13 9:32
Farhaneh9-Apr-13 9:32 
GeneralRe: integrating clips with c# Pin
Farhaneh9-Apr-13 9:33
Farhaneh9-Apr-13 9:33 
GeneralRe: integrating clips with c# Pin
Pete O'Hanlon9-Apr-13 9:35
mvePete O'Hanlon9-Apr-13 9:35 
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 

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.