using-directives

Duplicated using directives in multiple files

跟風遠走 提交于 2019-11-29 14:12:32
I have got 5 C# files that have 20 using directives in common. I want to get rid of this code duplication, especially because these 20 using directives belong logically together. In C or C++ I would have created an extra header file containing these 20 include files. This extra header file acts as a layer then to include the 20 other files in one go. Unfortunately I don't know how to do this in C#. Any suggestions? You can't do this in C# since C# does not have a preprocessor, and the C# compiler, although it supports some syntax that looks like preprocessor syntax, is handled by the compiler

VBA equivalent to C# using or VB.NET imports / creating aliases

浪子不回头ぞ 提交于 2019-11-29 10:26:52
Base Reference: Ten Code Conversions for VBA, Visual Basic .NET, and C# Note: I have already created and imported a *.dll , this question is about aliases . Let's say the programmatic name of a Test class is TestNameSpace.Test [ProgId("TestNamespace.Test")] public class Test ... Now, say a C# solution has been sealed and compiled into a *.dll and I'm referencing it in a Excel's VBE. Note: at this point I cannot modify the programmatic name as if the *.dll wasn't written by me. This is in VBA : Instead of declaring a variable like this: Dim myTest As TestNameSpace.Test Set myTest = new

Why is std:: used by experienced coders rather than using namespace std;? [duplicate]

时光怂恿深爱的人放手 提交于 2019-11-29 09:41:37
Possible Duplicate: Why is 'using namespace std;' considered a bad practice in C++? The other day when I asked a question someone replied saying if someone asks a question, show them the right way to do it instead of using namespace std; which I thought was a bit weird, as using namespace std; is way easier, But I guess I'm failing right now as I am a 'beginner' coder and you guys know better. So I guess my question is: Why std:: instead of using namespace std; ? Thanks. LumpN From C++ FAQ: Should I use using namespace std in my code? Probably not. People don't like typing std:: over and over,

What requires me to declare “using namespace std;”?

非 Y 不嫁゛ 提交于 2019-11-29 05:43:40
This question may be a duplicate, but I can't find a good answer. Short and simple, what requires me to declare using namespace std; in C++ programs? Since the C++ standard has been accepted, practically all of the standard library is inside the std namespace. So if you don't want to qualify all standard library calls with std:: , you need to add the using directive. However, using namespace std; is considered a bad practice because you are practically importing the whole standard namespace, thus opening up a lot of possibilities for name clashes. It is better to import only the stuff you are

distance calculation error in c++ [closed]

不羁的心 提交于 2019-11-29 05:22:48
#include <iostream> #include <cmath> #include <vector> using namespace std; int square(int a){ return a*a; } struct Point{ int x,y; }; int distance (const Point& a,const Point& b){ int k=(int) sqrt((float)((a.x-b.x)*(a.x-b.x))+((a.y-b.y)*(a.y-b.y))); return k; } int main(){ vector<Point>a(10); for (int i=0;i<10;i++){ cin>>a[i].x>>a[i].y; } int s=0; int s1; int k=0; for (int i=1;i<10;i++){ s+=square(distance(a[0],a[i])); } for (int i=1;i<10;i++){ s1=0; for (int j=0;j<10;j++){ s1+=square(distance(a[i],a[j])); if (s1<s) { s=s1; k=i;} } } cout<<k<<"Points are:"; cout<<a[k].x; cout<<a[k].y; return

What's This C# “using” directive?

吃可爱长大的小学妹 提交于 2019-11-29 03:41:13
I saw this C# using statement in a code example: using StringFormat=System.Drawing.StringFormat; What's that all about? That's aliasing a typename to a shorter name. The same syntax can also be used for aliasing namespaces. See using directive . (Updated in response to Richard) mbillard It's an alias , from now on, the user can use StringFormat to refer to System.Drawing.StringFormat . It's useful if you don't want to use the whole namespace (in case of name clash issues for example). source: using Directive article from MSDN Bullines Perhaps a different, unrelated StringFormat is declared in

The type or namespace cannot be found (are you missing a using directive or an assembly reference?)

喜你入骨 提交于 2019-11-28 13:18:11
I get the following error when I try to compile my C# program: The type or namespace name 'Login' could not be found (are you missing a using directive or an assembly reference?) using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace FootballLeague { public partial class MainMenu : Form { FootballLeagueDatabase footballLeagueDatabase; Game game; Team team; Login login; //Error here public MainMenu() { InitializeComponent(); changePanel(1); } public MainMenu

Default using directives in new C# files

只愿长相守 提交于 2019-11-28 09:05:23
Why does Visual Studio 2008 automatically insert the following using directives into each new C# file I create? using System; using System.Collections.Generic; using System.Text; What's so special about these namespaces? Are these the most frequently used ones? Jon Skeet Yes, they're frequently used, that's all, so MS put them in the Visual Studio templates . Personally I use "sort and remove unused usings" pretty frequently, so they often go away. If you want to remove them, you can amend the "new class" template . EDIT: If you become a fan of "Sort and Remove Unused Using Directives" you

Is a using-directive in a detail namespace problematic?

狂风中的少年 提交于 2019-11-28 08:39:22
问题 Consider this library header: #include<vector> #include<algorithm> #include<iostream> namespace Lib { namespace detail { using namespace std; template<class T> void sort_impl(istream &in,ostream &out) { vector<T> v; { int n; in >> n; v.resize(n); } for(auto &i : v) cin >> i; sort(v.begin(),v.end()); for(auto i : v) out << i << endl; } } inline void sort_std() { detail::sort_impl<int>(std::cin,std::cout); } } Does the detail namespace successfully isolate the clients of the library (and the

VBA equivalent to C# using or VB.NET imports / creating aliases

被刻印的时光 ゝ 提交于 2019-11-28 04:05:56
问题 Base Reference: Ten Code Conversions for VBA, Visual Basic .NET, and C# Note: I have already created and imported a *.dll , this question is about aliases . Let's say the programmatic name of a Test class is TestNameSpace.Test [ProgId("TestNamespace.Test")] public class Test ... Now, say a C# solution has been sealed and compiled into a *.dll and I'm referencing it in a Excel's VBE. Note: at this point I cannot modify the programmatic name as if the *.dll wasn't written by me. This is in VBA