473,322 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

C# Using and sub-items -- different from VB Using

I can't figure out how to do something in C# that can be done in VB (2005 for both). I have C# class for all my utility functions:

namespace CSharpUtilities
class Utilities
public string CSFunction1
public bool CSFunction2

I can have a VB application, and add CSharpUtilities as a separate project within the solution. and the Imports statement can be like "Imports CSharpUtilities.Utilities". Then I can use code like this in the VB program:

MyString = CSFunction1("Hello World")

or something like that. I don't have to qualify the function call to be

MyString = Utilities.CSFunction1("Hello World").

How do I get the ability to not have to qualify the function call (i.e. not add "Utilities." to the front of it) in C#?

C# will allow a "using CSharpUtilities;" but if I try to do "using CSharpUtilities.Utilities;" to get to where I was in VB, the compiler and IDE reject it. There is no way to be able to use the unqualified call and put

string MyString = CSFunction1("Hello World");

in C# that I can figure out. The only way this works is

string MyString = Utilities.CSFunction1("Hello World");

Does anyone know what I need to do to be able to use the unqualified Function call?

Thanks!
Mar 19 '08 #1
4 1171
balabaster
797 Expert 512MB
In VB you'd have used an Imports statement at the head of your code. C# has a similar statement - using.
VB
Expand|Select|Wrap|Line Numbers
  1. Imports MyUtilities
C#
Expand|Select|Wrap|Line Numbers
  1. Using MyUtilities;
Mar 19 '08 #2
In VB you'd have used an Imports statement at the head of your code. C# has a similar statement - using.
VB
Expand|Select|Wrap|Line Numbers
  1. Imports MyUtilities
C#
Expand|Select|Wrap|Line Numbers
  1. Using MyUtilities;
Yes, but is there a way in C# to be able to call the functions in another project without prefacing it with "Utilities." like you can with VB?
Mar 19 '08 #3
balabaster
797 Expert 512MB
Yes, but is there a way in C# to be able to call the functions in another project without prefacing it with "Utilities." like you can with VB?
I'm unsure - I'll have to investigate and get back to you.
Mar 19 '08 #4
Plater
7,872 Expert 4TB
In VB you used a "module" yes? An unclassified section of code.
In C# you can have static classes, but you still must refer to the class name first.

So if you have:
Expand|Select|Wrap|Line Numbers
  1. namespace MyNS
  2. {
  3.    public static class SomeClass
  4.    {
  5.       public int SomeFunc(string str)
  6.       {
  7.          return 1;
  8.       }
  9.    }
  10. }
  11.  
You can then use in a differnt project:
Expand|Select|Wrap|Line Numbers
  1. using MyNS;
  2.  
  3. public class myotherclass
  4. {
  5.    public myotherclass()
  6.    {
  7.       int n = SomeClass.SomeFunc("");
  8.    }
  9. }
  10.  
In other words, you can "using" any depth of namespaces, but you must refer to objects directly.
Mar 19 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: tshad | last post by:
I have an example I copied from "programming asp.net" (o'reilly) and can't seem to get the Sub (writefile) to execute. It displays all the response.write lines that are called directly, but not...
4
by: Terry | last post by:
The following code (VB6) automatically sets ticks or null values for Check Boxes: 'Pass' and/or 'Resit', depending on the data entered in the 'ModuleID' and 'Mark' Text Boxes. 'ModuleID' is a...
3
by: Kathy Burke | last post by:
Hi, I'm tired, so this question may be silly. I have a fairly long sub procedure. Based on one condition, I load another sub with the following: If Session("GRN") = "complete" Then txtScan.Text...
7
by: Doug | last post by:
An ASP.NET session cookie set on "www.mydomain.com" can not be accessed on "search.mydomain.com"; hence, a new session and cookie are being created on every sub-domain. This is occuring because...
3
by: andreas | last post by:
Hi, Is it possible to stop a sub in the middle waiting for a button clic to go further ? F.e. dim blnToStop as boolean private sub test ....... .......
3
by: simon | last post by:
I have sub and from tis sub I call another sub. If some condition is true then I would like to exit all subs not only the current one, which I can do with exit sub How can you do that? Private...
6
by: JC Voon | last post by:
Hi: The parent class have 3 version of constructor: public class Parent public sub New() end sub public sub New(i as integer) myclass.New()
6
by: Bob | last post by:
Hi, I found this code here below (about cartitems and shoppingcart) and I have two questions about sub New(). In the first class CartItem, there is two times sub New(): Public Sub New() End...
1
by: YotamElal | last post by:
Hello, I have a popup problem. When a popup is opened, I want all other popups to close immediatly. (except for its self and it's child popups) Here is my code: code: <!DOCTYPE HTML PUBLIC...
1
by: bemadragon | last post by:
Hello, I have been struggling with this for a while. I am working on a rather simple database for calculation purposes in Access 2003. I have a table called Order that has a primary key field...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.