CredentialCache Constructor
Collapse the table of content
Expand the table of content

CredentialCache Constructor ()


Creates a new instance of the CredentialCache class.

Namespace:   System.Net
Assembly:  System (in System.dll)

public CredentialCache()

The constructor creates a CredentialCache instance.

Legacy Code Example

The following code example initializes a CredentialCache with multiple security credentials and uses those credentials with a WebRequest.

// Define the namespaces used by this sample.
using System;
using System.Text;
using System.IO;
using System.Diagnostics;
using System.Threading;
using System.ComponentModel;

namespace ProcessAsyncStreamSamples
    class SortOutputRedirection
        // Define static variables shared by class methods.
        private static StringBuilder sortOutput = null;
        private static int numOutputLines = 0;

        public static void SortInputListText()
            // Initialize the process and its StartInfo properties.
            // The sort command is a console application that
            // reads and sorts text input.

            Process sortProcess;
            sortProcess = new Process();
            sortProcess.StartInfo.FileName = "Sort.exe";

            // Set UseShellExecute to false for redirection.
            sortProcess.StartInfo.UseShellExecute = false;

            // Redirect the standard output of the sort command.  
            // This stream is read asynchronously using an event handler.
            sortProcess.StartInfo.RedirectStandardOutput = true;
            sortOutput = new StringBuilder("");

            // Set our event handler to asynchronously read the sort output.
            sortProcess.OutputDataReceived += new DataReceivedEventHandler(SortOutputHandler);

            // Redirect standard input as well.  This stream
            // is used synchronously.
            sortProcess.StartInfo.RedirectStandardInput = true;

            // Start the process.

            // Use a stream writer to synchronously write the sort input.
            StreamWriter sortStreamWriter = sortProcess.StandardInput;

            // Start the asynchronous read of the sort output stream.

            // Prompt the user for input text lines.  Write each 
            // line to the redirected input stream of the sort command.
            Console.WriteLine("Ready to sort up to 50 lines of text");

            String inputText;
            int numInputLines = 0;
                Console.WriteLine("Enter a text line (or press the Enter key to stop):");

                inputText = Console.ReadLine();
                if (!String.IsNullOrEmpty(inputText))
                    numInputLines ++;
            while (!String.IsNullOrEmpty(inputText) && (numInputLines < 50));
            Console.WriteLine("<end of input stream>");

            // End the input stream to the sort command.

            // Wait for the sort process to write the sorted text lines.

            if (numOutputLines > 0)
                // Write the formatted and sorted output to the console.
                Console.WriteLine(" Sort results = {0} sorted text line(s) ", 
                Console.WriteLine(" No input lines were sorted.");


        private static void SortOutputHandler(object sendingProcess, 
            DataReceivedEventArgs outLine)
            // Collect the sort command output.
            if (!String.IsNullOrEmpty(outLine.Data))

                // Add the text to the collected output.
                sortOutput.Append(Environment.NewLine + 
                    "[" + numOutputLines.ToString() + "] - " + outLine.Data);

namespace ProcessAsyncStreamSamples

    class ProcessSampleMain
        /// The main entry point for the application.
        static void Main()
            catch (InvalidOperationException e)

Universal Windows Platform
Available since 4.5
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Windows Phone Silverlight
Available since 8.1
Windows Phone
Available since 8.1
Return to top
© 2015 Microsoft