title: Sharing Type from One Class in Other Classes
body: <p>I'm trying to make a class named <em>login class</em> that logs into a website and saves the cookies in a <code>cookiecontainer</code>. I then want to use the cookies saved in the <code>cookiecontainer</code> in other classes. I understand how to make a request and save the cookies in a <code>cookiecontainer</code>, however I do not know how to use the <code>cookiecontainer</code> in another class. Do I make the <code>cookiecontainer</code> a public shared type? How do I then access the cookies from this specific instance of the class?</p>
  
  <p><strong>CODE:</strong></p>
  
  <p>I am using code from <a href="http://howtostartprogramming.com/vb-net/vb-net-tutorial-52-httpwebrequest-cookiecontainer/" rel="nofollow">http://howtostartprogramming.com/vb-net/vb-net-tutorial-52-httpwebrequest-cookiecontainer/</a>.</p>
  
  <pre><code>Imports System.Net
  Imports System.Text
  Imports System.IO
  
  Public Class Login
  
      Public shared logincookie As CookieContainer
  
      Private Sub Login()
  
          Dim postData As String = "poststring"
          Dim tempCookies As New CookieContainer
          Dim encoding As New UTF8Encoding
          Dim byteData As Byte() = encoding.GetBytes(postData)
  
          Dim postReq As HttpWebRequest = DirectCast(WebRequest.Create("website"), HttpWebRequest)
          postReq.Method = "POST"
          postReq.KeepAlive = True
          postReq.CookieContainer = tempCookies
          postReq.ContentLength = byteData.Length
  
          Dim postreqstream As Stream = postReq.GetRequestStream()
          postreqstream.Write(byteData, 0, byteData.Length)
          postreqstream.Close()
          Dim postresponse As HttpWebResponse
  
          postresponse = DirectCast(postReq.GetResponse(), HttpWebResponse)
          tempCookies.Add(postresponse.Cookies)
          logincookie = tempCookies
  
      End Sub
  
  End Class
  </code></pre>